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

sandbox: AttributeError: 'bool' object has no attribute 'upper' #1624

Open
tomconte opened this issue Feb 18, 2025 · 0 comments
Open

sandbox: AttributeError: 'bool' object has no attribute 'upper' #1624

tomconte opened this issue Feb 18, 2025 · 0 comments

Comments

@tomconte
Copy link

System Info

❯ python --version
Python 3.11.9
❯ pip freeze | grep pandasai
pandasai==3.0.0b11
pandasai-docker==0.1.2
pandasai-openai==0.1.4

🐛 Describe the bug

Sometimes, when using the sandbox, the following failure happens.

Here is what I did:

class PandasAIAnalyzer:
    def __init__(self):
        # Initialize PandasAI with Azure LLM
        llm = PandasOpenAI(
            azure_endpoint=azure_endpoint,
            api_token=api_key,
            api_version=api_version,
            deployment_name=azure_deployment,
        )
        pandasai.config.set({"llm": llm})
        # Start the Docker sandbox
        self.sandbox = DockerSandbox()
        self.sandbox.start()
    
    def analyze(self, df: pd.DataFrame, question: str) -> pandasai.dataframe.base.BaseResponse:
        try:
            pai_df = pandasai.DataFrame(df)
            agent = pandasai.Agent(pai_df, sandbox=self.sandbox)
            result = agent.chat(question)
            return result
        except Exception as e:
            # Display full trace
            traceback.print_exc()
            return f"Error in PandasAI analysis: {str(e)}"

df is a simple dataframe with Timestamp/Value. The question was "Does the time series show any unusual trends?".

And the error:

Traceback (most recent call last):
  File "/var/folders/fy/2zls_q7526d7rk8xmp_kkcjh0000gn/T/ipykernel_29184/1296646968.py", line 29, in analyze
    result = agent.chat(question)
             ^^^^^^^^^^^^^^^^^^^^
  File "/Users/tconte/src/Cognite/cog-ai/.venv-notebooks/lib/python3.11/site-packages/pandasai/agent/base.py", line 92, in chat
    return self._process_query(query, output_type)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/tconte/src/Cognite/cog-ai/.venv-notebooks/lib/python3.11/site-packages/pandasai/agent/base.py", line 262, in _process_query
    result = self.execute_with_retries(code)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/tconte/src/Cognite/cog-ai/.venv-notebooks/lib/python3.11/site-packages/pandasai/agent/base.py", line 177, in execute_with_retries
    result = self.execute_code(code)
             ^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/tconte/src/Cognite/cog-ai/.venv-notebooks/lib/python3.11/site-packages/pandasai/agent/base.py", line 127, in execute_code
    return self._sandbox.execute(code, code_executor.environment)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/tconte/src/Cognite/cog-ai/.venv-notebooks/lib/python3.11/site-packages/pandasai/sandbox/sandbox.py", line 19, in execute
    return self._exec_code(code, environment)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/tconte/src/Cognite/cog-ai/.venv-notebooks/lib/python3.11/site-packages/pandasai_docker/docker_sandbox.py", line 119, in _exec_code
    sql_queries = self._extract_sql_queries_from_code(code)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/tconte/src/Cognite/cog-ai/.venv-notebooks/lib/python3.11/site-packages/pandasai/sandbox/sandbox.py", line 63, in _extract_sql_queries_from_code
    SQLQueryExtractor().visit(tree)
  File "/Users/tconte/.pyenv/versions/3.11.9/lib/python3.11/ast.py", line 418, in visit
    return visitor(node)
           ^^^^^^^^^^^^^
  File "/Users/tconte/.pyenv/versions/3.11.9/lib/python3.11/ast.py", line 426, in generic_visit
    self.visit(item)
  File "/Users/tconte/.pyenv/versions/3.11.9/lib/python3.11/ast.py", line 418, in visit
    return visitor(node)
           ^^^^^^^^^^^^^
  File "/Users/tconte/.pyenv/versions/3.11.9/lib/python3.11/ast.py", line 428, in generic_visit
    self.visit(value)
  File "/Users/tconte/.pyenv/versions/3.11.9/lib/python3.11/ast.py", line 418, in visit
    return visitor(node)
           ^^^^^^^^^^^^^
  File "/Users/tconte/src/Cognite/cog-ai/.venv-notebooks/lib/python3.11/site-packages/pandasai/sandbox/sandbox.py", line 57, in visit_Call
    if "SELECT" in arg.s.upper():
                   ^^^^^^^^^^^
AttributeError: 'bool' object has no attribute 'upper'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant