[bug] Fix SettingWithCopyWarning and export error #2481
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Link [Bug]stocks/ba/queries - google_view.py: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame. #1862
Screenshot of the feature or the bug before/after the fix, if applicable. N/A
Relevant motivation and context.
Nobody likes seeing warnings, we need to be assured that we're not inadvertently dropping relevant data from the DF in these functions.
List any dependencies that are required for this change.
none
How has this been tested?
Please describe the tests that you ran to verify your changes.
Compared raw output from the google_model to the actual output. I left a detailed explanation of the cause of the SettingWithCopyWarning in the issue.
TL;DR version - the warning only intermittently appears because of the varying data returned from google. Creating a copy of the original DF after filtering removes this warning.
Provide instructions so we can reproduce.
for changes in yfinance_model.py - unit tests already exist and continued to work
I tested the removal of the warning by running the following command before and after adding my changes
/stocks/options/chains
for changes to stocks/ba
I wrote a pytest called test_display_queries in test_google_view to compare the expected stdout. (I followed the Contributing guidelines for pytests visualizations)
I manually verified the output of the functions (prior to writing the pytest) with the following steps:
open a python terminal
import the following
get the response from google_model, save as gm_response
>>> gm_response = gm.get_queries('TSLA')
print the 'top' df from within gm_response
>>> gm_response['TSLA']['top']
run the following and verify that the top X values match the dict from the previous one
gv.display_queries('TSLA')
Checklist:
Others
pre-commit install
.pytest tests/...
.