Skip to content

TST: RollingGroupby.count with closed specified #36934

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/source/whatsnew/v1.2.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
^^^^^^^^^
Expand Down
32 changes: 32 additions & 0 deletions pandas/tests/window/test_grouper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)