-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
feat: workspace env #717
feat: workspace env #717
Conversation
fix(chart): charts to save to save_chart_path (Sourcery refactored)
WalkthroughThe changes introduced in this commit primarily revolve around the customization of the project root location and the saving of charts in the Changes
Poem
TipsChat with CodeRabbit Bot (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 0
Configuration used: CodeRabbit UI
Files selected for processing (6)
- examples/using_workspace_env.py (1 hunks)
- pandasai/helpers/code_manager.py (2 hunks)
- pandasai/helpers/path.py (2 hunks)
- pandasai/schemas/df_config.py (1 hunks)
- pandasai/smart_datalake/init.py (1 hunks)
- tests/test_smartdataframe.py (2 hunks)
Files skipped from review due to trivial changes (2)
- pandasai/helpers/path.py
- pandasai/schemas/df_config.py
Additional comments: 6
pandasai/helpers/code_manager.py (2)
8-8: The import statement for
find_project_root
is added correctly.236-245: The
execute_code
function is updated to handle the case whenself._config.save_charts
isFalse
. In this case, it calls theadd_save_chart
function withsave_charts_path_str
set to the result of thefind_project_root
function. This change introduces a new behavior when theelse
block is executed. Ensure that this new behavior is intended and does not introduce any unexpected side effects.tests/test_smartdataframe.py (2)
476-476: The new key-value pair "save_charts_path": "charts" has been added to the configuration dictionary. Ensure that the directory "charts" exists or is created before saving charts to it.
486-486: The assertion statement has been updated to check if the saved chart path matches the updated path "charts/{smart_dataframe.last_prompt_id}.png". Ensure that the
last_prompt_id
attribute is correctly set in thesmart_dataframe
object.pandasai/smart_datalake/__init__.py (1)
- 160-166: The code is trying to set the
save_charts_path
attribute of the_config
object to the correct directory path. This is done by joining the project root path (obtained fromfind_project_root()
) with the currentsave_charts_path
. Iffind_project_root()
raises aValueError
, it falls back to using the current working directory (os.getcwd()
). This change is consistent with the pull request's goal of allowing thepandasai
cache and charts to be stored in a different directory.examples/using_workspace_env.py (1)
- 1-38: The code looks good overall. However, ensure that the directory path assigned to the
PANDASAI_WORKSPACE
environment variable exists and is writable. Also, replace"YOUR_API_KEY"
with your actual API key. Be careful not to commit sensitive information like API keys to version control systems.
logger=self._logger, | ||
file_name="temp_chart", | ||
save_charts_path_str=find_project_root(), | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we really want this fallback in place? If save chart is false, we just should save it, what do you think?
pandasai/helpers/path.py
Outdated
@@ -2,6 +2,9 @@ | |||
|
|||
|
|||
def find_project_root(filename=None): | |||
if "PANDASAI_WORKSPACE" in os.environ: | |||
return os.environ["PANDASAI_WORKSPACE"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we can check it it's a valid path, otherwise raising an error?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 0
Configuration used: CodeRabbit UI
Files selected for processing (4)
- pandasai/exceptions.py (1 hunks)
- pandasai/helpers/code_manager.py (2 hunks)
- pandasai/helpers/path.py (2 hunks)
- pandasai/smart_datalake/init.py (2 hunks)
Files skipped from review due to trivial changes (1)
- pandasai/exceptions.py
Additional comments: 5
pandasai/helpers/code_manager.py (1)
- 236-246: The
execute_code
function has been updated to handle the case whenself._config.save_charts
isFalse
. In this case, it temporarily saves the generated chart to a directory determined by thefind_project_root
function. This is a good practice as it allows for temporary storage of charts for display without affecting the main chart saving functionality.pandasai/smart_datalake/__init__.py (2)
160-166: The code is trying to find the project root directory to save charts. If it fails, it falls back to the current working directory. This is a good practice as it provides a fallback mechanism in case the project root cannot be determined. However, it's important to ensure that the application has the necessary permissions to create directories and write files in these locations.
439-441: The
break
statement is used to exit the loop once the code is successfully executed. This is a good practice as it prevents unnecessary iterations of the loop.pandasai/helpers/path.py (2)
1-21: The code checks if the "PANDASAI_WORKSPACE" environment variable is set and if it points to a valid directory. If not, it raises an
InvalidWorkspacePathError
. This is a good practice as it allows users to customize the workspace path and provides clear error messages when the path is invalid.45-52: > Note: This review was outside of the patch, so it was mapped to the patch with the greatest overlap. Original lines [23-52]
The function
find_project_root
is used to find the root directory of the project. It starts from the current working directory and moves up the directory tree until it finds a directory containing one of the specified files ("pyproject.toml", "setup.py", "requirements.txt", "pandasai.json") or a custom filename if provided. If it doesn't find a project root, it returns the current working directory. This is a common and effective way to find the project root.
Codecov Report
❗ Your organization needs to install the Codecov GitHub app to enable full functionality. @@ Coverage Diff @@
## main #717 +/- ##
==========================================
- Coverage 85.39% 85.22% -0.17%
==========================================
Files 73 73
Lines 3553 3567 +14
==========================================
+ Hits 3034 3040 +6
- Misses 519 527 +8
... and 10 files with indirect coverage changes 📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
* feat(pipeline): Add pipeline to generate synthetic dataframe * chore(pipeline): maintain documentation and other flows * feat(Pipeline): test case for pipeline * feat(cache): adding cache in pipeline context and fix leftovers * chore(pipeline): rename and add dependency * update poetry lock file * refactor: minor changes from the code review Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * chore: update pipeline_context.py * chore: use PandasAI logger instead of default one * refactor: prompt for synthetic data now accepts the amount params * remove extra print statement * 'Refactored by Sourcery' (#703) Co-authored-by: Sourcery AI <> * chore(pipeline): improve pipeline usage remove passing config to pipeline * feat: config plot libraries (#705) * In this commit, I introduced a new configuration parameter in our application settings that allows users to define their preferred data visualization library (matplotlib, seaborn, or plotly). With this update, I've eliminated the need for the user to specify in every prompt which library to use, thereby simplifying their interaction with the application and increasing its versatility. * This commit adds a configuration parameter for users to set their preferred data visualization library (matplotlib, seaborn, or plotly), simplifying interactions and enhancing the application's versatility. * viz_library_type' in test_generate_python_code_prompt.py, resolved failing tests --------- Co-authored-by: sabatino.severino <qrxqfspfibrth6nxywai2qifza6jmskt222howzew43risnx4kva> Co-authored-by: Gabriele Venturi <[email protected]> * build: use ruff for formatting * feat: add add_message method to the agent * Release v1.4.3 * feat: workspace env (#717) * fix(chart): charts to save to save_chart_path * refactor sourcery changes * 'Refactored by Sourcery' * refactor chart save code * fix: minor leftovers * feat(workspace_env): add workspace env to store cache, temp chart and config * add error handling and comments --------- Co-authored-by: Sourcery AI <> --------- Co-authored-by: Gabriele Venturi <[email protected]> Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com> Co-authored-by: Sab Severino <[email protected]>
* feat: config plot libraries (#705) * In this commit, I introduced a new configuration parameter in our application settings that allows users to define their preferred data visualization library (matplotlib, seaborn, or plotly). With this update, I've eliminated the need for the user to specify in every prompt which library to use, thereby simplifying their interaction with the application and increasing its versatility. * This commit adds a configuration parameter for users to set their preferred data visualization library (matplotlib, seaborn, or plotly), simplifying interactions and enhancing the application's versatility. * viz_library_type' in test_generate_python_code_prompt.py, resolved failing tests --------- Co-authored-by: sabatino.severino <qrxqfspfibrth6nxywai2qifza6jmskt222howzew43risnx4kva> Co-authored-by: Gabriele Venturi <[email protected]> * build: use ruff for formatting * feat: add add_message method to the agent * Release v1.4.3 * feat: workspace env (#717) * fix(chart): charts to save to save_chart_path * refactor sourcery changes * 'Refactored by Sourcery' * refactor chart save code * fix: minor leftovers * feat(workspace_env): add workspace env to store cache, temp chart and config * add error handling and comments --------- Co-authored-by: Sourcery AI <> * fix: hallucinations was plotting when not asked * Release v1.4.4 * feat(sqlConnector): add direct config run sql at runtime * feat(DirectSqlConnector): add sql test cases * fix: minor leftovers * fix(orders): check examples of different tables * 'Refactored by Sourcery' * chore(sqlprompt): add description only when we have it --------- Co-authored-by: Sab Severino <[email protected]> Co-authored-by: Gabriele Venturi <[email protected]> Co-authored-by: Sourcery AI <>
Summary by CodeRabbit
New Features:
Agent
class to support chart plotting requests, improving data visualization capabilities.Refactor:
execute_code
function to handle chart saving scenarios more efficiently.Tests:
Chores:
df_config.py
, improving code cleanliness.