@@ -494,51 +494,32 @@ def test_mangled(self):
494
494
)
495
495
tm .assert_frame_equal (result , expected )
496
496
497
- def test_lambda_named_agg (self ):
498
- # see gh-28467
499
- animals = DataFrame (
500
- {
501
- "kind" : ["cat" , "dog" , "cat" , "dog" ],
502
- "height" : [9.1 , 6.0 , 9.5 , 34.0 ],
503
- "weight" : [7.9 , 7.5 , 9.9 , 198.0 ],
504
- }
505
- )
506
497
507
- result = animals .groupby ("kind" ).agg (
508
- mean_height = ("height" , "mean" ),
509
- perc90 = ("height" , lambda s : np .percentile (s , q = 0.90 )),
510
- )
511
- expected = DataFrame (
512
- [[9.3 , 9.1036 ], [20.0 , 6.252 ]],
513
- columns = ["mean_height" , "perc90" ],
514
- index = Index (["cat" , "dog" ], name = "kind" ),
515
- )
516
-
517
- tm .assert_frame_equal (result , expected )
498
+ def myfunc (s ):
499
+ return np .percentile (s , q = 0.90 )
518
500
519
- def test_func_named_agg (self ):
520
- # see gh-28467
521
- def myfunc (s ):
522
- return np .percentile (s , q = 0.90 )
523
501
524
- animals = DataFrame (
525
- {
526
- "kind" : ["cat" , "dog" , "cat" , "dog" ],
527
- "height" : [9.1 , 6.0 , 9.5 , 34.0 ],
528
- "weight" : [7.9 , 7.5 , 9.9 , 198.0 ],
529
- }
530
- )
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
+ )
531
512
532
- result = animals .groupby ("kind" ).agg (
533
- mean_height = ("height" , "mean" ), perc90 = ("height" , myfunc )
534
- )
535
- expected = DataFrame (
536
- [[9.3 , 9.1036 ], [20.0 , 6.252 ]],
537
- columns = ["mean_height" , "perc90" ],
538
- index = Index (["cat" , "dog" ], name = "kind" ),
539
- )
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
+ )
540
521
541
- tm .assert_frame_equal (result , expected )
522
+ tm .assert_frame_equal (result , expected )
542
523
543
524
544
525
class TestLambdaMangling :
0 commit comments