@@ -495,6 +495,33 @@ def test_mangled(self):
495
495
tm .assert_frame_equal (result , expected )
496
496
497
497
498
+ def myfunc (s ):
499
+ return np .percentile (s , q = 0.90 )
500
+
501
+
502
+ @pytest .mark .parametrize ("func" , [lambda s : np .percentile (s , q = 0.90 ), myfunc ])
503
+ def test_lambda_named_agg (func ):
504
+ # see gh-28467
505
+ animals = DataFrame (
506
+ {
507
+ "kind" : ["cat" , "dog" , "cat" , "dog" ],
508
+ "height" : [9.1 , 6.0 , 9.5 , 34.0 ],
509
+ "weight" : [7.9 , 7.5 , 9.9 , 198.0 ],
510
+ }
511
+ )
512
+
513
+ result = animals .groupby ("kind" ).agg (
514
+ mean_height = ("height" , "mean" ), perc90 = ("height" , func )
515
+ )
516
+ expected = DataFrame (
517
+ [[9.3 , 9.1036 ], [20.0 , 6.252 ]],
518
+ columns = ["mean_height" , "perc90" ],
519
+ index = Index (["cat" , "dog" ], name = "kind" ),
520
+ )
521
+
522
+ tm .assert_frame_equal (result , expected )
523
+
524
+
498
525
class TestLambdaMangling :
499
526
def test_maybe_mangle_lambdas_passthrough (self ):
500
527
assert _maybe_mangle_lambdas ("mean" ) == "mean"
0 commit comments