diff --git a/doc/source/whatsnew/v1.2.0.rst b/doc/source/whatsnew/v1.2.0.rst index ae4d5ea692066..0ab95dd260a9c 100644 --- a/doc/source/whatsnew/v1.2.0.rst +++ b/doc/source/whatsnew/v1.2.0.rst @@ -442,6 +442,7 @@ Groupby/resample/rolling - Bug in :meth:`Rolling.sum()` returned wrong values when dtypes where mixed between float and integer and axis was equal to one (:issue:`20649`, :issue:`35596`) - Bug in :meth:`Rolling.count` returned ``np.nan`` with :class:`pandas.api.indexers.FixedForwardWindowIndexer` as window, ``min_periods=0`` and only missing values in window (:issue:`35579`) - Bug where :class:`pandas.core.window.Rolling` produces incorrect window sizes when using a ``PeriodIndex`` (:issue:`34225`) +- Bug in :meth:`RollingGroupby.count` where a ``ValueError`` was raised when specifying the ``closed`` parameter (:issue:`35869`) Reshaping ^^^^^^^^^ diff --git a/pandas/tests/window/test_grouper.py b/pandas/tests/window/test_grouper.py index d69ee72a00aee..63bf731e95096 100644 --- a/pandas/tests/window/test_grouper.py +++ b/pandas/tests/window/test_grouper.py @@ -472,3 +472,35 @@ def test_groupby_rolling_no_sort(self): index=pd.MultiIndex.from_tuples([(2, 0), (1, 1)], names=["foo", None]), ) tm.assert_frame_equal(result, expected) + + def test_groupby_rolling_count_closed_on(self): + # GH 35869 + df = pd.DataFrame( + { + "column1": range(6), + "column2": range(6), + "group": 3 * ["A", "B"], + "date": pd.date_range(end="20190101", periods=6), + } + ) + result = ( + df.groupby("group") + .rolling("3d", on="date", closed="left")["column1"] + .count() + ) + expected = pd.Series( + [np.nan, 1.0, 1.0, np.nan, 1.0, 1.0], + name="column1", + index=pd.MultiIndex.from_tuples( + [ + ("A", pd.Timestamp("2018-12-27")), + ("A", pd.Timestamp("2018-12-29")), + ("A", pd.Timestamp("2018-12-31")), + ("B", pd.Timestamp("2018-12-28")), + ("B", pd.Timestamp("2018-12-30")), + ("B", pd.Timestamp("2019-01-01")), + ], + names=["group", "date"], + ), + ) + tm.assert_series_equal(result, expected)