Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

type object 'datetime.datetime' has no attribute 'datetime' #1254

Open
ssling0817 opened this issue Jun 26, 2024 · 1 comment
Open

type object 'datetime.datetime' has no attribute 'datetime' #1254

ssling0817 opened this issue Jun 26, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@ssling0817
Copy link

ssling0817 commented Jun 26, 2024

System Info

pandasai version 2.0.42

馃悰 Describe the bug

When I input question related to date time, it will generate code using datetime library, but it often encounters this error. I guess sometimes it will confuse between import datetime and from datetime import datetime?

AttributeError: type object 'datetime.datetime' has no attribute 'datetime'

[INFO] Code generated:

import datetime

# Assuming dfs[0] is your DataFrame
filtered_df = dfs[0][(dfs[0]['priority'].isin(['P0 - Critical', 'P1 - High'])) & (dfs[0]['created'] >= datetime.datetime.now() - datetime.timedelta(days=30)) & (dfs[0]['created'] < datetime.datetime.now() - datetime.timedelta(days=7))]
result_df = filtered_df[['epic_id', 'priority', 'summary', 'created']]
result = {'type': 'dataframe', 'value': result_df}

[INFO] Executing Step 2: CodeCleaning
[INFO] Code running:

filtered_df = dfs[0][dfs[0]['priority'].isin(['P0 - Critical', 'P1 - High']) & (dfs[0]['created'] >= datetime.datetime.now() - datetime.timedelta(days=30)) & (dfs[0]['created'] < datetime.datetime.now() - datetime.timedelta(days=7))]
result_df = filtered_df[['epic_id', 'priority', 'summary', 'created']]
result = {'type': 'dataframe', 'value': result_df}
@dosubot dosubot bot added the bug Something isn't working label Jun 26, 2024
Copy link

dosubot bot commented Jun 26, 2024

To resolve the AttributeError: type object 'datetime.datetime' has no attribute 'datetime' error, ensure that you are correctly importing and using the datetime module. The correct way to import and use the datetime module is as follows:

import datetime

# Correct usage
current_time = datetime.datetime.now()
print(current_time)

Make sure you are not using datetime.datetime.datetime, which would cause the AttributeError. The correct usage is datetime.datetime.

In your generated code, the import statement is correct, but double-check that there are no conflicting imports or incorrect usages elsewhere in your code. Here is the corrected version of your generated code:

import datetime

# Assuming dfs[0] is your DataFrame
filtered_df = dfs[0][(dfs[0]['priority'].isin(['P0 - Critical', 'P1 - High'])) & 
                     (dfs[0]['created'] >= datetime.datetime.now() - datetime.timedelta(days=30)) & 
                     (dfs[0]['created'] < datetime.datetime.now() - datetime.timedelta(days=7))]
result_df = filtered_df[['epic_id', 'priority', 'summary', 'created']]
result = {'type': 'dataframe', 'value': result_df}

Ensure that your imports and usage are consistent with these examples to avoid the AttributeError [1].

To continue talking to Dosu, mention @dosu.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant