Fix ValueError when comparing Series with scalar (Issue #448)#450
Merged
Conversation
- Fixed _get_baseline_value() function to properly handle both DataFrame and Series inputs - When prices is a DataFrame, iloc[0] returns a Series requiring additional indexing - When prices is a Series, iloc[0] returns a scalar directly - Updated version to 0.0.68 - Cleaned up temporary test files 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR fixes a ValueError that occurred when generating HTML reports with certain data types. The issue was in the _get_baseline_value() function which didn't properly handle cases where prices.iloc[0] could return either a scalar (Series input) or a Series (DataFrame input).
- Fixed type checking in
_get_baseline_value()to handle both DataFrame and Series inputs correctly - Updated version number to 0.0.68
- Added changelog entry documenting the fix
Reviewed Changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| quantstats/stats.py | Added type checking to handle DataFrame vs Series inputs in _get_baseline_value() function |
| quantstats/version.py | Bumped version from 0.0.67 to 0.0.68 |
| CHANGELOG.md | Added entry for version 0.0.68 documenting the fix |
| test_*.py files | Removed temporary test files used during development |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
_get_baseline_value()function to properly handle both DataFrame and Series inputsProblem
When calling
qs.reports.html()with certain data, the code would fail with a ValueError in the_get_baseline_value()function. The issue occurred becauseprices.iloc[0]can return either a scalar (when prices is a Series) or a Series (when prices is a DataFrame), but the code was trying to compare this directly with numeric values.Solution
Added proper type checking to handle both cases:
pricesis a DataFrame,iloc[0]returns a Series, so we need an additional.iloc[0]to get the scalar valuepricesis a Series,iloc[0]returns a scalar directlyTest plan
Fixes #448
🤖 Generated with Claude Code