reflex
reflex copied to clipboard
PD.DataFrame is not supported for State
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
Looking into this now
This is a bug on our side will be fixing asap
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
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,
),

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
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 I'm seeing this too - working on a fix now.
What's the right way to instantiate a pandas dataframe in rx.State? Still seem to be getting errors with this approach.