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
as the above return type is a dictionary, not a dataframe, leading to this error:
2024-12-31 10:26:04 [ERROR] Pipeline failed on step 6: 'dict' object has no attribute 'to_json'
Traceback (most recent call last):
File "...pandasai/pipelines/chat/generate_chat_pipeline.py", line 335, in run
).run(input)
^^^^^^^^^^
File "...pandasai/pipelines/pipeline.py", line 137, in run
raise e
File "...pandasai/pipelines/pipeline.py", line 101, in run
step_output = logic.execute(
^^^^^^^^^^^^^^
File "...pandasai/pipelines/chat/code_execution.py", line 133, in execute
{"content_type": "response", "value": ResponseSerializer.serialize(result)},
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "...pandasai/responses/response_serializer.py", line 27, in serialize
df_dict = ResponseSerializer.serialize_dataframe(result["value"])
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "...pandasai/responses/response_serializer.py", line 11, in serialize_dataframe
json_data = json.loads(df.to_json(orient="split", date_format="iso"))
^^^^^^^^^^
AttributeError: 'dict' object has no attribute 'to_json'
Note that this problem can be partially solved with strong prompting - still it happens sometimes anyway.
The text was updated successfully, but these errors were encountered:
Hey there, @francler! I'm here to help you with any bugs, questions, or contributions. Let's tackle this together!
The issue you're encountering arises because the ResponseSerializer class in PandasAI is expecting a DataFrame, but the code generated by PandasAI is returning a dictionary of DataFrames. The serialize_dataframe method is trying to call to_json on a dictionary, which leads to the AttributeError.
To address this, you need to modify the handling of the result in the ResponseSerializer class to accommodate dictionaries of DataFrames. Here's a potential approach:
Modify the serialize Method: Update the serialize method to check if the result["value"] is a dictionary. If it is, iterate over the dictionary and serialize each DataFrame individually.
This modification checks if the value is a dictionary and then serializes each DataFrame within it. This should resolve the error you're facing by ensuring that each DataFrame in the dictionary is correctly serialized before being returned.
System Info
pandasai==2.4.1
python==3.12.2
ProductName: macOS
ProductVersion: 15.1.1
BuildVersion: 24B91
🐛 Describe the bug
I am using PandasAI in a complex codebase. Note that I am creating an Agent with two data frames with different columns:
where
df_1
anddf_2
are valid pandas dataframes.Sometimes, for some queries, PandasAI generates code like this:
Once executed, the return type of this function collides with the command in line 11 of the file
pandasai/responses/response_serializer.py
:as the above return type is a dictionary, not a dataframe, leading to this error:
Note that this problem can be partially solved with strong prompting - still it happens sometimes anyway.
The text was updated successfully, but these errors were encountered: