Skip to content

Commit 8c7ef13

Browse files
michaelchuclaude
andcommitted
Fix pandas 3.0 compatibility for groupby aggregation
Change observed=False to observed=True in _group_by_intervals() to fix test failures on Python 3.11/3.12 with pandas 3.0. The new pandas version returns all category combinations (including empty ones) when observed=False, causing aggregation to return hundreds of rows instead of the expected grouped results. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 57edb3a commit 8c7ef13

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

optopsy/core.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,9 @@ def _group_by_intervals(
174174
) -> pd.DataFrame:
175175
"""Group options by intervals and calculate descriptive statistics."""
176176
# this is a bottleneck, try to optimize
177-
grouped_dataset = data.groupby(cols, observed=False)["pct_change"].describe()
177+
# Use observed=True to only return groups with actual data (avoids pandas 3.0
178+
# issue where observed=False returns all category combinations as empty rows)
179+
grouped_dataset = data.groupby(cols, observed=True)["pct_change"].describe()
178180

179181
# if any non-count columns return NaN remove the row
180182
if drop_na:

0 commit comments

Comments
 (0)