Skip to content

Commit 8caf5cc

Browse files
ranaroussiCopilot
andauthored
Handling empty DataFrames or DataFrames with no columns
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 5027b8a commit 8caf5cc

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

quantstats/stats.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2146,7 +2146,10 @@ def _get_baseline_value(prices):
21462146

21472147
# Handle both Series and DataFrame cases
21482148
if isinstance(prices, _pd.DataFrame):
2149-
# If prices is a DataFrame, get the first value of the first column
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
21502153
first_price = prices.iat[0, 0]
21512154
else:
21522155
# If prices is a Series, get the first value directly

0 commit comments

Comments
 (0)