@@ -323,15 +323,22 @@ def test_transform_transformation_func(transformation_func):
323
323
{
324
324
"A" : ["foo" , "foo" , "foo" , "foo" , "bar" , "bar" , "baz" ],
325
325
"B" : [1 , 2 , np .nan , 3 , 3 , np .nan , 4 ],
326
- }
326
+ },
327
+ index = pd .date_range ("2020-01-01" , "2020-01-07" ),
327
328
)
328
329
329
- if transformation_func in [ "pad" , "backfill" , "tshift" , " cumcount"] :
330
- # These transformation functions are not yet covered in this test
331
- pytest . xfail ( "See GH 31269" )
330
+ if transformation_func == " cumcount" :
331
+ test_op = lambda x : x . transform ( "cumcount" )
332
+ mock_op = lambda x : Series ( range ( len ( x )), x . index )
332
333
elif transformation_func == "fillna" :
333
334
test_op = lambda x : x .transform ("fillna" , value = 0 )
334
335
mock_op = lambda x : x .fillna (value = 0 )
336
+ elif transformation_func == "tshift" :
337
+ msg = (
338
+ "Current behavior of groupby.tshift is inconsistent with other "
339
+ "transformations. See GH34452 for more details"
340
+ )
341
+ pytest .xfail (msg )
335
342
else :
336
343
test_op = lambda x : x .transform (transformation_func )
337
344
mock_op = lambda x : getattr (x , transformation_func )()
@@ -340,7 +347,10 @@ def test_transform_transformation_func(transformation_func):
340
347
groups = [df [["B" ]].iloc [:4 ], df [["B" ]].iloc [4 :6 ], df [["B" ]].iloc [6 :]]
341
348
expected = concat ([mock_op (g ) for g in groups ])
342
349
343
- tm .assert_frame_equal (result , expected )
350
+ if transformation_func == "cumcount" :
351
+ tm .assert_series_equal (result , expected )
352
+ else :
353
+ tm .assert_frame_equal (result , expected )
344
354
345
355
346
356
def test_transform_select_columns (df ):
0 commit comments