Skip to content

Fix ValueError when comparing Series with scalar (Issue #448)#450

Merged
ranaroussi merged 3 commits into
mainfrom
fix-issue-448
Jul 22, 2025
Merged

Fix ValueError when comparing Series with scalar (Issue #448)#450
ranaroussi merged 3 commits into
mainfrom
fix-issue-448

Conversation

@ranaroussi
Copy link
Copy Markdown
Owner

Summary

  • Fixed _get_baseline_value() function to properly handle both DataFrame and Series inputs
  • Resolves ValueError: "The truth value of a Series is ambiguous" when generating HTML reports
  • Cleaned up temporary test files

Problem

When calling qs.reports.html() with certain data, the code would fail with a ValueError in the _get_baseline_value() function. The issue occurred because prices.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:

  • When prices is a DataFrame, iloc[0] returns a Series, so we need an additional .iloc[0] to get the scalar value
  • When prices is a Series, iloc[0] returns a scalar directly

Test plan

Fixes #448

🤖 Generated with Claude Code

- 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>
@ranaroussi ranaroussi requested a review from Copilot July 22, 2025 10:41
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment thread quantstats/stats.py
Comment thread quantstats/stats.py Outdated
Comment thread quantstats/stats.py Outdated
ranaroussi and others added 2 commits July 22, 2025 11:49
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@ranaroussi ranaroussi merged commit 32aa0b6 into main Jul 22, 2025
3 of 55 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().

2 participants