Skip to content

Commit 136353f

Browse files
authored
TST: RollingGroupby.count with closed specified (#36934)
1 parent 9787744 commit 136353f

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

doc/source/whatsnew/v1.2.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,7 @@ Groupby/resample/rolling
442442
- 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`)
443443
- 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`)
444444
- Bug where :class:`pandas.core.window.Rolling` produces incorrect window sizes when using a ``PeriodIndex`` (:issue:`34225`)
445+
- Bug in :meth:`RollingGroupby.count` where a ``ValueError`` was raised when specifying the ``closed`` parameter (:issue:`35869`)
445446

446447
Reshaping
447448
^^^^^^^^^

pandas/tests/window/test_grouper.py

+32
Original file line numberDiff line numberDiff line change
@@ -472,3 +472,35 @@ def test_groupby_rolling_no_sort(self):
472472
index=pd.MultiIndex.from_tuples([(2, 0), (1, 1)], names=["foo", None]),
473473
)
474474
tm.assert_frame_equal(result, expected)
475+
476+
def test_groupby_rolling_count_closed_on(self):
477+
# GH 35869
478+
df = pd.DataFrame(
479+
{
480+
"column1": range(6),
481+
"column2": range(6),
482+
"group": 3 * ["A", "B"],
483+
"date": pd.date_range(end="20190101", periods=6),
484+
}
485+
)
486+
result = (
487+
df.groupby("group")
488+
.rolling("3d", on="date", closed="left")["column1"]
489+
.count()
490+
)
491+
expected = pd.Series(
492+
[np.nan, 1.0, 1.0, np.nan, 1.0, 1.0],
493+
name="column1",
494+
index=pd.MultiIndex.from_tuples(
495+
[
496+
("A", pd.Timestamp("2018-12-27")),
497+
("A", pd.Timestamp("2018-12-29")),
498+
("A", pd.Timestamp("2018-12-31")),
499+
("B", pd.Timestamp("2018-12-28")),
500+
("B", pd.Timestamp("2018-12-30")),
501+
("B", pd.Timestamp("2019-01-01")),
502+
],
503+
names=["group", "date"],
504+
),
505+
)
506+
tm.assert_series_equal(result, expected)

0 commit comments

Comments
 (0)