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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use pandas instead of RestrictedPandas #1470

Open
XJTU-JP opened this issue Dec 12, 2024 · 6 comments
Open

use pandas instead of RestrictedPandas #1470

XJTU-JP opened this issue Dec 12, 2024 · 6 comments
Labels
bug Something isn't working

Comments

@XJTU-JP
Copy link

XJTU-JP commented Dec 12, 2024

System Info

pandas 1.5.3
pandasai 2.4.0

🐛 Describe the bug

I want the agent to use panda instead of RestrictedPandas. What should be done

raise AttributeError(f"'{name}' is not allowed in RestrictedPandas")
AttributeError: 'DateOffset' is not allowed in RestrictedPandas

@dosubot dosubot bot added the bug Something isn't working label Dec 12, 2024
Copy link

dosubot bot commented Dec 12, 2024

Hey @XJTU-JP! I'm here to help you with that. Let's tackle this together!

To use regular pandas instead of RestrictedPandas in the pandas-ai library, you can configure the library to use the regular pandas engine. You can do this by using the set_pd_engine function. Here's how you can set it up:

from pandasai.engine import set_pd_engine

set_pd_engine("pandas")

This will ensure that the library uses the standard pandas package instead of RestrictedPandas [1][2].

To continue talking to Dosu, mention @dosu.


Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Other

@XJTU-JP
Copy link
Author

XJTU-JP commented Dec 12, 2024

Hello, we tried to solve the issue.

This is what we did:

Modified the RestrictedPandas class to include 'DateOffset' in the allowed_attributes list. This change allows the use of 'DateOffset' within the RestrictedPandas environment, addressing the AttributeError raised when trying to use this pandas feature.

You can review changes in this commit: kkpo4553@89f17e8.

Caution

Disclaimer: The concept of solution was created by AI and you should never copy paste this code before you check the correctness of generated code. Solution might not be complete, you should use this code as an inspiration only.

If you no longer want Latta AI to attempt solving issues on your repository, you can block this account.

This solution solved my problem. In addition
The agent can't find the library when executing the code. How to solve this problem?
Can you give me some suggestions
eg..

    exec(code, environment)
  File "<string>", line 7, in <module>
  File "<string>", line 7, in <listcomp>
NameError: name 'timedelta' is not defined

2024-12-12 15:25:35 [ERROR] Pipeline failed on step 6: name 'timedelta' is not defined

@phoenixor
Copy link

i got the same error ‘Timestamp’ is not allowed in RestrictedPandas with pandasai 2.4.0
i upload a xlsx file with some hospital data and ask How many hospitals are involved in the table? the ai answers: Unfortunately, I was xxxxx error: ‘Timestamp’ is not allowed in RestrictedPandas.
i wonder is it because pandasai use pandas of version 1.5.3, it is too old, the latest version is 2.2

@XJTU-JP
Copy link
Author

XJTU-JP commented Dec 12, 2024

i got the same error ‘Timestamp’ is not allowed in RestrictedPandas with pandasai 2.4.0 i upload a xlsx file with some hospital data and ask How many hospitals are involved in the table? the ai answers: Unfortunately, I was xxxxx error: ‘Timestamp’ is not allowed in RestrictedPandas. i wonder is it because pandasai use pandas of version 1.5.3, it is too old, the latest version is 2.2

I have this problem and I have a solution. You can modify the source code directly, similar to the operation shown in the pic, but this may result in code injection (although it is highly unlikely).

the file path is "site-packages/pandasai/safe_libs/restricted_pandas.py"

image

@ArslanSaleem
Copy link
Collaborator

ArslanSaleem commented Dec 12, 2024

@XJTU-JP
You can use config to whitelist timedelta if you want to allow it because of the security concerns PandasAI allow mininmum libs required to do analysis.

config={"custom_whitelisted_dependencies": ["timedelta"]

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

4 participants
@phoenixor @ArslanSaleem @XJTU-JP and others