Sanitize priceToBook for mixed currencies #2632
Open
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.
Changes were made to address Issue #2593:
Added _sanitize_price_to_book() helper method in quote.py (lines 614-631). This method detects when currency and financialCurrency fields differ in the info dictionary. When mismatched currencies are detected AND priceToBook exists, it sets priceToBook to None. This prevents propagating invalid price-to-book ratios caused by Yahoo's backend computing ratios with mismatched currencies. Other fields (currentPrice, bookValue, currency, financialCurrency) remain unchanged
Integrated sanitization call in _fetch_info() method (line 690). After the info dictionary is fully populated and formatted, _sanitize_price_to_book() is called. This ensures all raw data from Yahoo is processed for currency mismatches before being returned to users.
Added regression test in test_ticker.py (lines 1054-1129).
Test Results: All key tests pass: