You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
%load_extcudf.pandasimportpandasaspdfrompandasaiimportSmartDataframedf=pd.DataFrame({"a":[0,1,2]})
df=SmartDataframe(df)
---------------------------------------------------------------------------ValueErrorTraceback (mostrecentcalllast)
CellIn[2], line52frompandasaiimportSmartDataframe4df=pd.DataFrame({"a":[0,1,2]})
---->5df=SmartDataframe(df)
File~/rapids-2310/lib/python3.10/site-packages/pandasai/smart_dataframe/__init__.py:277, inSmartDataframe.__init__(self, df, name, description, sample_head, config, logger)
275ifdescriptionisNone:
276description=df_config["description"]
-->277self._core=SmartDataframeCore(df, logger)
279self._table_description=description280self._table_name=nameFile~/rapids-2310/lib/python3.10/site-packages/pandasai/smart_dataframe/__init__.py:64, inSmartDataframeCore.__init__(self, df, logger)
62def__init__(self, df: DataFrameType, logger: Logger=None):
63self._logger=logger--->64self._load_dataframe(df)
File~/rapids-2310/lib/python3.10/site-packages/pandasai/smart_dataframe/__init__.py:93, inSmartDataframeCore._load_dataframe(self, df)
89raiseValueError(
90"Invalid input data. We cannot convert it to a dataframe."91 ) frome92else:
--->93self.dataframe=dfFile~/rapids-2310/lib/python3.10/site-packages/pandasai/smart_dataframe/__init__.py:208, inSmartDataframeCore.dataframe(self, df)
205self._df=df207ifdfisnotNone:
-->208self._load_engine()
File~/rapids-2310/lib/python3.10/site-packages/pandasai/smart_dataframe/__init__.py:124, inSmartDataframeCore._load_engine(self)
121engine=df_type(self._df)
123ifengineisNone:
-->124raiseValueError(
125"Invalid input data. Must be a Pandas or Polars dataframe."126 )
128self._engine=engineValueError: Invalidinputdata. MustbeaPandasorPolarsdataframe.
The error is surprising. It's not in the stacktrace because the function causing the error doesn't throw, it just returns None instead of "pandas". We're failing in this function:
defdf_type(df: DataFrameType) ->Union[str, None]:
""" Returns the type of the dataframe. Args: df (DataFrameType): Pandas or Polars dataframe Returns: str: Type of the dataframe """ifpolars_importedandisinstance(df, pl.DataFrame):
return"polars"elifisinstance(df, pd.DataFrame):
return"pandas"else:
returnNone
Seems like we should pass, right? When I rip the function out of the module and run it in my notebook, it works smoothly. But in the pandasai module, it fails.
The following print statements I added to the pandasai module code suggest something is going wrong:
defdf_type(df: DataFrameType) ->Union[str, None]:
""" Returns the type of the dataframe. Args: df (DataFrameType): Pandas or Polars dataframe Returns: str: Type of the dataframe """print(pd)
print(f"type(type(df)): {type(type(df))}")
print(f"type(pd.DataFrame): {type(pd.DataFrame)}")
print(f"isinstance(df, pd.DataFrame): {isinstance(df, pd.DataFrame)}")
ifpolars_importedandisinstance(df, pl.DataFrame):
return"polars"elifisinstance(df, pd.DataFrame):
return"pandas"else:
returnNone
I've been testing pandasai (docs) with
cudf.pandas
and experienced a surprising error.This code works:
But this doesn't:
The error is surprising. It's not in the stacktrace because the function causing the error doesn't throw, it just returns None instead of "pandas". We're failing in this function:
Seems like we should pass, right? When I rip the function out of the module and run it in my notebook, it works smoothly. But in the pandasai module, it fails.
The following print statements I added to the pandasai module code suggest something is going wrong:
pd.DataFrame
is referring to the rawpd.DataFrame
, not a wrapped proxy. So theisinstance
check returns False.In a chat this morning, @shwina wondered if this might be happening because the module name starts with "pandas"!
The text was updated successfully, but these errors were encountered: