@@ -272,14 +272,30 @@ def test_combined_up_downsampling_of_irregular():
272
272
tm .assert_series_equal (result , expected )
273
273
274
274
275
- def test_transform ():
276
-
275
+ def test_transform_series ():
277
276
r = test_series .resample ("20min" )
278
277
expected = test_series .groupby (pd .Grouper (freq = "20min" )).transform ("mean" )
279
278
result = r .transform ("mean" )
280
279
tm .assert_series_equal (result , expected )
281
280
282
281
282
+ @pytest .mark .parametrize ("on" , [None , "date" ])
283
+ def test_transform_frame (on ):
284
+ # GH#47079
285
+ index = date_range (datetime (2005 , 1 , 1 ), datetime (2005 , 1 , 10 ), freq = "D" )
286
+ index .name = "date"
287
+ df = DataFrame (np .random .rand (10 , 2 ), columns = list ("AB" ), index = index )
288
+ expected = df .groupby (pd .Grouper (freq = "20min" )).transform ("mean" )
289
+ if on == "date" :
290
+ # Move date to being a column; result will then have a RangeIndex
291
+ expected = expected .reset_index (drop = True )
292
+ df = df .reset_index ()
293
+
294
+ r = df .resample ("20min" , on = on )
295
+ result = r .transform ("mean" )
296
+ tm .assert_frame_equal (result , expected )
297
+
298
+
283
299
def test_fillna ():
284
300
285
301
# need to upsample here
@@ -390,7 +406,8 @@ def test_agg():
390
406
expected = pd .concat ([a_mean , a_std , b_mean , b_std ], axis = 1 )
391
407
expected .columns = pd .MultiIndex .from_product ([["A" , "B" ], ["mean" , "std" ]])
392
408
for t in cases :
393
- warn = FutureWarning if t in cases [1 :3 ] else None
409
+ # In case 2, "date" is an index and a column, so agg still tries to agg
410
+ warn = FutureWarning if t == cases [2 ] else None
394
411
with tm .assert_produces_warning (
395
412
warn ,
396
413
match = r"\['date'\] did not aggregate successfully" ,
@@ -660,12 +677,11 @@ def test_selection_api_validation():
660
677
661
678
exp = df_exp .resample ("2D" ).sum ()
662
679
exp .index .name = "date"
663
- msg = "The default value of numeric_only"
664
- with tm .assert_produces_warning (FutureWarning , match = msg ):
665
- result = df .resample ("2D" , on = "date" ).sum ()
680
+ result = df .resample ("2D" , on = "date" ).sum ()
666
681
tm .assert_frame_equal (exp , result )
667
682
668
683
exp .index .name = "d"
684
+ msg = "The default value of numeric_only"
669
685
with tm .assert_produces_warning (FutureWarning , match = msg ):
670
686
result = df .resample ("2D" , level = "d" ).sum ()
671
687
tm .assert_frame_equal (exp , result )
0 commit comments