Skip to content

Commit 32aa0b6

Browse files
authored
Merge pull request #450 from ranaroussi/fix-issue-448
Fix ValueError when comparing Series with scalar (Issue #448)
2 parents 592949a + 8caf5cc commit 32aa0b6

8 files changed

Lines changed: 17 additions & 1282 deletions

File tree

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
Changelog
22
===========
33

4+
0.0.68
5+
------
6+
7+
- Fixed ValueError when comparing Series with scalar in _get_baseline_value() function (fixes issue #448)
8+
- Properly handle both DataFrame and Series inputs in drawdown calculations
9+
410
0.0.67
511
------
612

quantstats/stats.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2144,7 +2144,16 @@ def _get_baseline_value(prices):
21442144
if len(prices) == 0:
21452145
return 1.0
21462146

2147-
first_price = prices.iloc[0]
2147+
# Handle both Series and DataFrame cases
2148+
if isinstance(prices, _pd.DataFrame):
2149+
# If prices is a DataFrame, ensure it has at least one column
2150+
if prices.shape[1] == 0:
2151+
return 1.0 # Default baseline for empty DataFrame with no columns
2152+
# Get the first value of the first column
2153+
first_price = prices.iat[0, 0]
2154+
else:
2155+
# If prices is a Series, get the first value directly
2156+
first_price = prices.iloc[0]
21482157

21492158
# If the first price is much larger than 1, it's likely from to_prices conversion
21502159
# The to_prices function uses base * (1 + compsum), so we determine the appropriate baseline

quantstats/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
version = "0.0.67"
1+
version = "0.0.68"

test_drawdown_fix.py

Lines changed: 0 additions & 308 deletions
This file was deleted.

0 commit comments

Comments
 (0)