-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Random KeyError happening during code execution with correct code #1544
Comments
Hey @hbrantner-auvaria! I'm here to help you with your bug. I'm a bot that can assist you with bug fixes, answer your questions, and help you become a contributor. Let's tackle this issue together! A similar issue has been reported where a To continue talking to Dosu, mention @dosu. Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Other |
also while giving the agent information about a dataframe, the common type pd.StringDtype() is displayed as object, but should be displayed as string in my opinion, furthermore the addition of a nullable property for each column would be nice: name: PortName |
Another thing that I found out is that timestamps are incorrectly presented to the LLM in the samples: name: EstimatedArrivalTime |
If you point me to the locations I may be able to fix it myself, I think the df is inserted with the templates, but I currently have no good overview over the project |
The conversion of pandas data types to string representations for the LLM is handled by the For the issue with Regarding the incorrect presentation of timestamps, the The templates used to insert dataframe information into the chat pipeline are located in To continue talking to Dosu, mention @dosu. Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Other |
@dosu Can I skip the code cleaning step? |
Skipping the code cleaning step is not recommended, as it helps prevent the execution of potentially dangerous code by removing unsafe built-ins like To continue talking to Dosu, mention @dosu. Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Other |
Furthermore, also the kind of errors are happening @dosu:
What do you suggest? |
For the errors you're encountering:
Consider reviewing the To continue talking to Dosu, mention @dosu. Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Other |
@dosu What is wrong here, I do not get it ... You generated this python code: |
The To address this issue, you can try the following:
If the code itself is correct and the error persists, it might be necessary to look into how the execution environment is configured and whether any security settings are overly restrictive for your use case. To continue talking to Dosu, mention @dosu. Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Other |
Another example @dosu You generated this python code: |
The To address this issue, consider the following steps:
If the code itself is correct and the error persists, it might be necessary to look into how the execution environment is configured and whether any security settings are overly restrictive for your use case. To continue talking to Dosu, mention @dosu. Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Other |
cannot import code in exec - disabled code cleaning step and set security to 'none' - do not understand where the problem comes from @ArslanSaleem @gventuri : Generate python code and return full updated code: INFO:pandasai.helpers.logger:Code generated: import pandas as pd
import datetime
import pytz
def format_time(dt):
if pd.isna(dt):
return "Not specified"
return dt.strftime("%H:%M")
# Get current date in UTC
current_date = datetime.datetime.now(pytz.UTC)
current_date_start = current_date.replace(hour=0, minute=0, second=0, microsecond=0)
current_date_end = current_date.replace(hour=23, minute=59, second=59, microsecond=999999)
# Filter events for today
daily_events_df = dfs[5] # DailyEvents table
todays_events = daily_events_df[
(daily_events_df['EventStart'] >= current_date_start) &
(daily_events_df['EventStart'] <= current_date_end)
]
if len(todays_events) == 0:
response = "There are no events scheduled for today."
else:
# Sort events by start time
todays_events = todays_events.sort_values('EventStart')
# Create formatted event list
event_list = []
for _, event in todays_events.iterrows():
event_str = (f"{format_time(event['EventStart'])} - {format_time(event['EventEnd'])}: "
f"{event['EventName']} ({event['EventLocation']})")
if pd.notna(event['EventPriceInEur']):
event_str += f" - {event['EventPriceInEur']}€"
event_list.append(event_str)
response = "Today's events:\n\n" + "\n".join(event_list)
result = {
"type": "string",
"value": response
} INFO:pandasai.helpers.logger:Executing Step 4: CachePopulation |
This seemed to fix it, after digging in the library code: But that should not be so complicated ... or so error-prone in the default config |
Hi @hbrantner-auvaria we are aware there are some stability issues with date times and are further investigating in a robust way to fix it! Thanks a lot for the very detailed logs, much appreciated, we'll investigate further from there! |
System Info
pandas AI 2.4.2
mac OS 15.2
Python 3.12.8
AWS Bedrock as LLM with Claude 3.5 Sonnet v2
🐛 Describe the bug
@ArslanSaleem @gventuri
This is the log that I get in my console if I ask my agent: "What is the current date?" I have no data sources attached ...
Why do I get the KeyError here, code seems to be just fine. I do not understand why such easy use case is not working.
You generated this python code:
current_date = datetime.datetime.now(datetime.timezone.utc)
formatted_date = current_date.strftime('%A, %B %d, %Y')
result = {'type': 'string', 'value': f"Today's date is {formatted_date}."}
It fails with the following error:
Traceback (most recent call last):
File "/Users/hannes_brantner/Library/Caches/pypoetry/virtualenvs/chatbot-fXCp8fhr-py3.12/lib/python3.12/site-packages/pandasai/pipelines/chat/code_execution.py", line 85, in execute
result = self.execute_code(code_to_run, code_context)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/hannes_brantner/Library/Caches/pypoetry/virtualenvs/chatbot-fXCp8fhr-py3.12/lib/python3.12/site-packages/freezegun/api.py", line 885, in wrapper
result = func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "/Users/hannes_brantner/Library/Caches/pypoetry/virtualenvs/chatbot-fXCp8fhr-py3.12/lib/python3.12/site-packages/pandasai/pipelines/chat/code_execution.py", line 174, in execute_code
exec(code, environment)
File "", line 2, in
KeyError: 'import'
Do you have an idea why this happens?
The text was updated successfully, but these errors were encountered: