Skip to content

Commit 53b58e8

Browse files
mroeschkeMatt Roeschke
and
Matt Roeschke
authored
TST: RollingGroupby(..., center=True, on=...) (#37154)
Co-authored-by: Matt Roeschke <[email protected]>
1 parent c2a96c6 commit 53b58e8

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

pandas/tests/window/test_grouper.py

+35
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,41 @@ def test_groupby_rolling_center_center(self):
297297
)
298298
tm.assert_frame_equal(result, expected)
299299

300+
def test_groupby_rolling_center_on(self):
301+
# GH 37141
302+
df = pd.DataFrame(
303+
data={
304+
"Date": pd.date_range("2020-01-01", "2020-01-10"),
305+
"gb": ["group_1"] * 6 + ["group_2"] * 4,
306+
"value": range(10),
307+
}
308+
)
309+
result = (
310+
df.groupby("gb")
311+
.rolling(6, on="Date", center=True, min_periods=1)
312+
.value.mean()
313+
)
314+
expected = Series(
315+
[1.0, 1.5, 2.0, 2.5, 3.0, 3.5, 7.0, 7.5, 7.5, 7.5],
316+
name="value",
317+
index=pd.MultiIndex.from_tuples(
318+
(
319+
("group_1", pd.Timestamp("2020-01-01")),
320+
("group_1", pd.Timestamp("2020-01-02")),
321+
("group_1", pd.Timestamp("2020-01-03")),
322+
("group_1", pd.Timestamp("2020-01-04")),
323+
("group_1", pd.Timestamp("2020-01-05")),
324+
("group_1", pd.Timestamp("2020-01-06")),
325+
("group_2", pd.Timestamp("2020-01-07")),
326+
("group_2", pd.Timestamp("2020-01-08")),
327+
("group_2", pd.Timestamp("2020-01-09")),
328+
("group_2", pd.Timestamp("2020-01-10")),
329+
),
330+
names=["gb", "Date"],
331+
),
332+
)
333+
tm.assert_series_equal(result, expected)
334+
300335
@pytest.mark.parametrize("min_periods", [5, 4, 3])
301336
def test_groupby_rolling_center_min_periods(self, min_periods):
302337
# GH 36040

0 commit comments

Comments
 (0)