reflex icon indicating copy to clipboard operation
reflex copied to clipboard

PD.DataFrame is not supported for State

Open qu3vipon opened this issue 2 years ago • 6 comments

Describe the bug pd.DataFrame type is not supported for State

To Reproduce

class State(pc.State):
   data: pd.DataFrame

Error Message

$ TypeError: State vars must be primitive Python types, Plotly figures, Pandas dataframes, or subclasses of pc.Base. Found var “data” with type <class ‘pandas.core.frame.DataFrame’>.

Code

  • couldn’t find pd.DataFrame in Valid state var types
# pynecone/utils.py L60

# Valid state var types
PrimitiveType = Union[int, float, bool, str, list, dict, tuple]
StateVar = Union[PrimitiveType, Base, None]

Specifics (please complete the following information):

  • Python Version: 3.8.10
  • Pynecone Version: 0.1.12
  • OS: mac OS

qu3vipon avatar Jan 18 '23 05:01 qu3vipon

Looking into this now

Alek99 avatar Jan 19 '23 03:01 Alek99

This is a bug on our side will be fixing asap

Alek99 avatar Jan 19 '23 04:01 Alek99

In the mean time it seems computed vars for pandas is working see this example, https://github.com/pynecone-io/pynecone-examples/blob/main/nba/nba/nba.py

Alek99 avatar Jan 19 '23 04:01 Alek99

In the mean time it seems computed vars for pandas is working see this example, https://github.com/pynecone-io/pynecone-examples/blob/main/nba/nba/nba.py

@Alek99 When I used the computed var in the data_table's data prop I am getting this error. Is this also a bug?

            pc.data_table(
                data=State.df,
                pagination=True,
                search=True,
                sort=True,
                resizable=True,
            ),
image

wongni avatar Jan 22 '23 19:01 wongni

Hmm just ran the example and it seems to be working for me what pynecone version are you on and did you change the code at all

Alek99 avatar Jan 22 '23 19:01 Alek99

Hmm just ran the example and it seems to be working for me what pynecone version are you on and did you change the code at all

I am using pynecone 0.1.13 version and python 3.9.13 version. And the only code I changed in the nba example's main branch was from data=nba_data, to data=State.df,. I tried both Firefox and Chrome browsers on Mac but still got An error happened while fetching the data error on the table.

wongni avatar Jan 23 '23 16:01 wongni

@wongni I'm seeing this too - working on a fix now.

picklelo avatar Jan 24 '23 01:01 picklelo

What's the right way to instantiate a pandas dataframe in rx.State? Still seem to be getting errors with this approach.

rohitsathish avatar Dec 07 '23 05:12 rohitsathish