Skip to content

Commit 38121bf

Browse files
author
Marco Gorelli
committed
make sure exclusions are applied before the groupby object reaches rolling
1 parent 24827e5 commit 38121bf

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

pandas/core/window/common.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ def __init__(self, obj, *args, **kwargs):
5252
kwargs.pop("parent", None)
5353
groupby = kwargs.pop("groupby", None)
5454
if groupby is None:
55-
groupby, obj = obj, obj.obj
55+
groupby, obj = obj, obj._obj_with_exclusions
56+
groupby.obj = obj
5657
self._groupby = groupby
5758
self._groupby.mutated = True
5859
self._groupby.grouper.mutated = True

pandas/tests/window/test_rolling.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,3 +465,13 @@ def test_rolling_count_default_min_periods_with_null_values(constructor):
465465
result = constructor(values).rolling(3).count()
466466
expected = constructor(expected_counts)
467467
tm.assert_equal(result, expected)
468+
469+
470+
def test_by_column_not_in_values():
471+
# GH 32262
472+
df = pd.DataFrame({"A": [1] * 20 + [2] * 12 + [3] * 8, "B": np.arange(40)})
473+
474+
g = df.groupby("A")
475+
r = g.rolling(4)
476+
result = r.sum()
477+
assert "A" not in result.columns

0 commit comments

Comments
 (0)