-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
fix(connectors): make sqlalchemy non-optional and check yfinance imports #561
Conversation
WalkthroughThe changes primarily focus on optimizing the usage of Changes
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
Files ignored due to filter (1)
- pyproject.toml
Files selected for processing (1)
- pandasai/connectors/yahoo_finance.py (5 hunks)
Additional comments (Suppressed): 5
pandasai/connectors/yahoo_finance.py (5)
1-4: The import statement for
yfinance
has been removed from the top of the file. This is in line with the PR summary and seems to be a good practice to ensure that the code fails gracefully when the required package is not installed.16-23: The
__init__
method now includes a try-except block to check for the availability of theyfinance
package and raises an error if it's not installed. This is a good practice as it ensures that the code fails gracefully when the required package is not installed.36-36: The
Ticker
object fromyfinance
is now initialized in the__init__
method using the_config.table
value, and stored inself.ticker
. This change is in line with the PR summary and seems to be a good practice as it allows theTicker
object to be reused across methods, reducing unnecessary overhead and potential inconsistencies.46-47: The
head
method now uses theTicker
object stored inself.ticker
to retrieve the head data. This is a good practice as it reuses theTicker
object initialized in the__init__
method, reducing unnecessary overhead and potential inconsistencies.114-117: The
execute
method now uses theTicker
object stored inself.ticker
to retrieve the stock data. This is a good practice as it reuses theTicker
object initialized in the__init__
method, reducing unnecessary overhead and potential inconsistencies.
@mspronesti thanks a lot, definitely better. Glad to discuss about the yahoo finance implementation. Feel free to open a discussion or an issue for that! |
* fix(connectors): make sqlalchemy non-optional and check yfinance imports (#561) * feat: use duckdb for the cache * Release v1.2.2 * feat: `output_type` parameter (#519) * (feat): update prompt template in `GeneratePythonCodePrompt`, add `output_type_hint` variable to be interpolated * (feat): update `.chat()` method for `SmartDataframe` and `SmartDatalake`, add optional `output_type` parameter * (feat): add `get_output_type_hint()` in `GeneratePythonCodePrompt` class * (feat): add "output_type_hint" to `default_values` when forming prompt's template context * (tests): update tests in `TestGeneratePythonCodePrompt` * (tests): add tests for checking `output_type` interpotaion to a prompt * refactor: `output_type` parameter (#519) * (refactor): update setting value for `{output_type_hint}` in prompt class * fix: `output_type` parameter (#519) * (tests): fix error in `TestGeneratePythonCodePrompt` with confused actual prompt's content and excepted prompt's content (which led to tests being failed) * (refactor): update test method `test_str_with_args()` with `parametrize` decorator, remove duplication of code (DRY) * tests: `output_type` parameter (#519) * (tests): parametrizing `test_run_passing_output_type()` with different output types. * refactor: `output_type` parameter (#519) * (refactor): move output types and their hints to a separate python module * (feat): validation for inappropriate output type and value * (tests): update tests accordingly, add a new test method to check if the message about incorrect output type is added to logs * chore: `output_type` parameter (#519) * (chore): remove unused lines * refactor: `output_type` parameter (#519) * (refactor): pass `output_type_hint` in the `default_values`, don't bother with setting this template variable in prompt's `__init__()` * (fix): correct templates examples, add them as a part of `output_type_hint` * (refactor): use `df_type()` (utility functions) to get rid from imports of third packages in _output_types.py * (refactor): add logging to the factory-function `output_type_factory()` to enhance verbosity for behaviour inspection ---------
Hi @gventuri,
this PR aims at solving #558. Please notice however that there are something that don't add up to me in the implementation of yahoo finance and that it might be the case to check (unrelated to this PR, perhaps in another?).
Summary by CodeRabbit
Refactor:
yfinance
package inyahoo_finance.py
. The changes ensure that aTicker
object is created only once during initialization, improving performance and reducing unnecessary object creation.yfinance
package. This provides a clear error message if the required package is not installed.Bug Fix:
Ticker
objects were unnecessarily created in thehead
andexecute
methods. Now, these methods utilize theTicker
object created during initialization, leading to more efficient code execution.