Skip to content

Conversation

matteocacciola
Copy link
Contributor

@matteocacciola matteocacciola commented Aug 20, 2025


Important

Adds Plotly support for interactive charts, updates templates, and includes tests for new functionality.

  • Behavior:
    • Adds Plotly support in get_environment() in environment.py.
    • Removes plt.show() and fig.show() lines in clean_code() in code_cleaning.py.
    • Replaces output filenames with temporary JSON paths in _replace_output_filenames_with_temp_json_chart() in code_cleaning.py.
    • Removes directory creation commands except for default chart directory in _remove_make_dirs() in code_cleaning.py.
  • Templates:
    • Updates generate_python_code_with_sql.tmpl and output_type_template.tmpl to include "iplot" type.
  • Models:
    • Adds InteractiveChartResponse class in interactive_chart.py.
    • Updates ResponseParser in parser.py to handle "iplot" type.
  • Dependencies:
    • Adds plotly to pyproject.toml.
  • Tests:
    • Adds tests for Plotly support in test_environment.py.
    • Adds tests for JSON chart handling in test_code_cleaning.py.
    • Adds tests for InteractiveChartResponse in test_interactive_chart_response.py.
    • Updates test_responses.py and test_sql_prompt.py for new "iplot" type.

This description was created by Ellipsis for b8d05fa. You can customize this summary. It will automatically update as commits are pushed.

@Copilot Copilot AI review requested due to automatic review settings August 20, 2025 11:55
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds support for interactive charts using Plotly alongside existing matplotlib chart functionality. The changes introduce a new "iplot" output type for Plotly charts, add necessary dependencies, and update templates and prompts to handle the new chart type.

  • Adds InteractiveChartResponse class for handling Plotly chart data
  • Integrates Plotly dependencies (plotly.express as "px" and plotly.graph_objects as "go")
  • Updates response parsing to support "iplot" type for interactive charts

Reviewed Changes

Copilot reviewed 14 out of 15 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
tests/unit_tests/response/test_interactive_chart_response.py Comprehensive test suite for the new InteractiveChartResponse class
tests/unit_tests/prompts/test_sql_prompt.py Updates prompt tests to include "iplot" type and fixes typo
tests/unit_tests/helpers/test_responses.py Adds tests for interactive plot parsing and validation
tests/unit_tests/helpers/test_optional_dependency.py Adds assertion for "px" dependency in environment
tests/unit_tests/core/code_generation/test_code_cleaning.py Tests for JSON chart file handling and directory creation removal
tests/unit_tests/core/code_execution/test_environment.py Adds assertion for "px" dependency in environment tests
pyproject.toml Adds plotly dependency to project requirements
pandasai/core/response/parser.py Updates response parser to handle "iplot" type
pandasai/core/response/interactive_chart.py New InteractiveChartResponse class implementation
pandasai/core/response/init.py Exports the new InteractiveChartResponse class
pandasai/core/prompts/templates/shared/output_type_template.tmpl Updates template to include "iplot" type with typo fix
pandasai/core/prompts/templates/generate_python_code_with_sql.tmpl Fixes typo in SQL template
pandasai/core/code_generation/code_cleaning.py Adds JSON chart handling and directory creation removal
pandasai/core/code_execution/environment.py Adds Plotly dependencies to execution environment

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Copy link
Contributor

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Changes requested ❌

Reviewed everything up to b8d05fa in 2 minutes and 33 seconds. Click for details.
  • Reviewed 522 lines of code in 14 files
  • Skipped 1 files when reviewing.
  • Skipped posting 5 draft comments. View those below.
  • Modify your settings and rules to customize what types of comments Ellipsis leaves. And don't forget to react with 👍 or 👎 to teach Ellipsis.
1. pandasai/core/response/interactive_chart.py:19
  • Draft comment:
    Opening the file in binary mode ('rb') for JSON parsing might cause issues since json.load expects a text stream. Consider using 'r' or wrapping the binary stream with a text decoder.
  • Reason this comment was not posted:
    Decided after close inspection that this draft comment was likely wrong and/or not actionable: usefulness confidence = 20% vs. threshold = 50% While technically both "r" and "rb" modes can work with json.load(), using text mode "r" is more conventional and clearer for JSON files since they are text-based. However, json.load() can handle both text and binary file objects, as it will decode binary streams automatically. The change isn't strictly necessary for functionality. The comment might be too pedantic since the code would work fine either way. Also, in some cases, binary mode can be preferable for handling different line endings consistently across platforms. While the code works with either mode, using text mode "r" better reflects the nature of JSON files and follows more conventional Python practices. The comment should be deleted as it suggests a change that isn't strictly necessary for functionality and doesn't address any real issues or risks.
2. tests/unit_tests/core/code_generation/test_code_cleaning.py:232
  • Draft comment:
    Possible formatting issue in the f-string for the default chart directory: the quotes seem mismatched. Consider using consistent quoting, e.g., f"os.makedirs('{DEFAULT_CHART_DIRECTORY}')\nplt.show()\nfig.show()".
  • Reason this comment was not posted:
    Marked as duplicate.
3. pandasai/core/prompts/templates/shared/output_type_template.tmpl:2
  • Draft comment:
    Typographical error: Consider changing "plotly" si used to "plotly" is used.
  • Reason this comment was not posted:
    Marked as duplicate.
4. tests/unit_tests/core/code_generation/test_code_cleaning.py:236
  • Draft comment:
    Typo: The f-string in this line also has mismatched quotes: f"os.mkdir({DEFAULT_CHART_DIRECTORY}')\nplt.show()\nfig.show()" It would likely be correct to have it as: f"os.mkdir('{DEFAULT_CHART_DIRECTORY}')\nplt.show()\nfig.show()"
  • Reason this comment was not posted:
    Marked as duplicate.
5. tests/unit_tests/prompts/test_sql_prompt.py:24
  • Draft comment:
    Typographical error: In the string, "plotly" si used should be "plotly" is used.
  • Reason this comment was not posted:
    Marked as duplicate.

Workflow ID: wflow_eZWWPMVJQlGQWSdd

You can customize Ellipsis by changing your verbosity settings, reacting with 👍 or 👎, replying to comments, or adding code review rules.

@ArslanSaleem
Copy link
Collaborator

ArslanSaleem commented Sep 30, 2025

@matteocacciola Thank you for the PR! We’re not planning to add interactive charts to PandasAI. Feel free to submit a PR to improve the prompt.

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

Successfully merging this pull request may close these issues.

Getting the plot data to create an interactive chart based on the X,Y co ordinates

2 participants