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

Plot chart failing on windows #1593

Open
pulkitmehtawork opened this issue Feb 6, 2025 · 6 comments
Open

Plot chart failing on windows #1593

pulkitmehtawork opened this issue Feb 6, 2025 · 6 comments

Comments

@pulkitmehtawork
Copy link

pulkitmehtawork commented Feb 6, 2025

Env: Windows 10 Pro
Pandas AI version: 3.0.0b8
Python version : 3.11.9

`
import pandasai as pai
from pandasai_openai import AzureOpenAI
from pandasai import Agent
#removed key, end point
llm = AzureOpenAI(
api_token="",
azure_endpoint = "",
deployment_name="gpt-4o",
api_version="2024-02-15-preview") # The name of your deployed model

pai.config.set({"llm": llm})
df = pai.read_csv("data/heart.csv")
agent = Agent(df,config={
"llm": llm,
"verbose": True,
"save_charts": True,
"open_charts": False,
"save_charts_path": "/exports/charts/",
})
response = agent.chat("Plot age frequency.")
print(response)

`

When I load 1 csv in pandasai and query - plot the age frequency . It throws below error .
Seems to be path issue in windows. Please check .

Error stack trace :

plot_filename = plot_age_frequency()
result = {'type': 'plot', 'value': plot_filename}
2025-02-06 16:39:10 [INFO] Retrying execution (1/3)...
2025-02-06 16:39:10 [INFO] Execution failed with error: Traceback (most recent call last):
File "C:\Users\pulkitme\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\pandasai\core\code_execution\code_executor.py", line 29, in execute
exec(code, self._environment)
File "", line 20, in
File "", line 15, in plot_age_frequency
File "C:\Users\pulkitme\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\matplotlib\pyplot.py", line 1023, in savefig
res = fig.savefig(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\pulkitme\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\matplotlib\figure.py", line 3378, in savefig
self.canvas.print_figure(fname, **kwargs)
File "C:\Users\pulkitme\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\matplotlib\backend_bases.py", line 2366, in print_figure
result = print_method(
^^^^^^^^^^^^^
File "C:\Users\pulkitme\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\matplotlib\backend_bases.py", line 2232, in
print_method = functools.wraps(meth)(lambda *args, **kwargs: meth(
^^^^^
File "C:\Users\pulkitme\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\matplotlib\backends\backend_agg.py", line 509, in print_png
self._print_pil(filename_or_obj, "png", pil_kwargs, metadata)
File "C:\Users\pulkitme\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\matplotlib\backends\backend_agg.py", line 458, in _print_pil
mpl.image.imsave(
File "C:\Users\pulkitme\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\matplotlib\image.py", line 1689, in imsave
image.save(fname, **pil_kwargs)
File "C:\Users\pulkitme\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\PIL\Image.py", line 2563, in save
fp = builtins.open(filename, "w+b")
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
OSError: [Errno 22] Invalid argument: 'C:\pandasai\exports\charts\temp_chart.png'

@gdcsinaptik
Copy link
Collaborator

Hi @pulkitmehtawork please edit your original ticket so that:

  • you state your version of Windows
  • you state the version of PandasAI you are using
  • you share the snippet of code that is throwing the error
  • you format properly the code using the brackets in editor.

Thanks!

@pulkitmehtawork
Copy link
Author

Hi @pulkitmehtawork please edit your original ticket so that:

  • you state your version of Windows
  • you state the version of PandasAI you are using
  • you share the snippet of code that is throwing the error
  • you format properly the code using the brackets in editor.

Thanks!

Done.

@gdcsinaptik
Copy link
Collaborator

What about using this code rather than the agent?

Let me know what happens using directly the chat method on the panda-ai dataframe or, alternatively

import pandasai as pai`
from pandasai_openai import AzureOpenAI


llm = AzureOpenAI(
api_token="",
azure_endpoint = "",
deployment_name="gpt-4o",
api_version="2024-02-15-preview") # The name of your deployed model

pai.config.set({"llm": llm})

df = pai.read_csv("data/heart.csv")

response = df.chat("Plot age frequency")

For more details and understanding the 3.0, please read: https://docs.getpanda.ai/v3/chat-and-output

@pulkitmehtawork
Copy link
Author

What about using this code rather than the agent?

Let me know what happens using directly the chat method on the panda-ai dataframe or, alternatively

import pandasai as pai`
from pandasai_openai import AzureOpenAI


llm = AzureOpenAI(
api_token="",
azure_endpoint = "",
deployment_name="gpt-4o",
api_version="2024-02-15-preview") # The name of your deployed model

pai.config.set({"llm": llm})

df = pai.read_csv("data/heart.csv")

response = df.chat("Plot age frequency")

For more details and understanding the 3.0, please read: https://docs.getpanda.ai/v3/chat-and-output

Still the same error .

@gdcsinaptik
Copy link
Collaborator

We will investigate the issue. Thanks @pulkitmehtawork

@faresmalik
Copy link

faresmalik commented Feb 10, 2025

Hello dear, I have fixed the issue by changing the hard coded name of the image. since it is temp_chart, once changed to ..\temp_chart.png windows deal with it as \t.

Solution: Go to source code and change the temp_chart.png to chart_temp.png. This should work!

@gdcsinaptik a quick suggestion, including uuid and letting the name of the image be a dynamic every call is very beneficial. By this, you will keep all generated images stored properly rather than overriding them! To do so, I have removed the temp_chart.png and replace it with f"{uuid}.png".

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

3 participants