@@ -297,6 +297,41 @@ def test_groupby_rolling_center_center(self):
297
297
)
298
298
tm .assert_frame_equal (result , expected )
299
299
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
+
300
335
@pytest .mark .parametrize ("min_periods" , [5 , 4 , 3 ])
301
336
def test_groupby_rolling_center_min_periods (self , min_periods ):
302
337
# GH 36040
0 commit comments