@@ -486,9 +486,6 @@ def test_groupby_agg_dict_dup_columns():
486486 tm .assert_frame_equal (result , expected )
487487
488488
489- @pytest .mark .filterwarnings (
490- "ignore:In the future, using the non-aggregation func:DeprecationWarning"
491- )
492489@pytest .mark .parametrize (
493490 "op" ,
494491 [
@@ -568,9 +565,7 @@ def test_order_aggregate_multiple_funcs():
568565 # GH 25692
569566 df = DataFrame ({"A" : [1 , 1 , 2 , 2 ], "B" : [1 , 2 , 3 , 4 ]})
570567
571- msg = "using the non-aggregation func='ohlc' will raise"
572- with tm .assert_produces_warning (DeprecationWarning , match = msg ):
573- res = df .groupby ("A" ).agg (["sum" , "max" , "mean" , "ohlc" , "min" ])
568+ res = df .groupby ("A" ).agg (["sum" , "max" , "mean" , "ohlc" , "min" ])
574569 result = res .columns .levels [1 ]
575570
576571 expected = Index (["sum" , "max" , "mean" , "ohlc" , "min" ])
@@ -1176,6 +1171,22 @@ def test_with_kwargs(self):
11761171 expected = DataFrame ({"<lambda_0>" : [13 ], "<lambda_1>" : [30 ]})
11771172 tm .assert_frame_equal (result , expected )
11781173
1174+ def test_unused_kwargs (self ):
1175+ # GH#39169 - Passing kwargs used to have agg pass the entire frame rather
1176+ # than column-by-column
1177+
1178+ # UDF that works on both the entire frame and column-by-column
1179+ func = lambda data , ** kwargs : np .sum (np .sum (data ))
1180+
1181+ df = DataFrame ([[1 , 2 ], [3 , 4 ]])
1182+ expected = DataFrame ({0 : [1 , 3 ], 1 : [2 , 4 ]})
1183+
1184+ result = df .groupby (level = 0 ).agg (func )
1185+ tm .assert_frame_equal (result , expected )
1186+
1187+ result = df .groupby (level = 0 ).agg (func , foo = 42 )
1188+ tm .assert_frame_equal (result , expected )
1189+
11791190 def test_agg_with_one_lambda (self ):
11801191 # GH 25719, write tests for DataFrameGroupby.agg with only one lambda
11811192 df = DataFrame (
@@ -1262,6 +1273,40 @@ def test_agg_multiple_lambda(self):
12621273 )
12631274 tm .assert_frame_equal (result2 , expected )
12641275
1276+ def test_multiple_udf_same_name (self ):
1277+ # GH#28570
1278+ quant50 = partial (np .percentile , q = 50 )
1279+ quant70 = partial (np .percentile , q = 70 )
1280+
1281+ df = DataFrame ({"col1" : ["a" , "a" , "b" , "b" , "b" ], "col2" : [1 , 2 , 3 , 4 , 5 ]})
1282+ expected = DataFrame (
1283+ [[1.5 , 1.7 ], [4.0 , 4.4 ]],
1284+ index = Index (["a" , "b" ], name = "col1" ),
1285+ columns = MultiIndex (
1286+ levels = [["col2" ], ["percentile" ]],
1287+ codes = [[0 , 0 ], [0 , 0 ]],
1288+ ),
1289+ )
1290+ gb = df .groupby ("col1" )
1291+ result = gb .agg ({"col2" : [quant50 , quant70 ]})
1292+ tm .assert_frame_equal (result , expected )
1293+
1294+ @pytest .mark .parametrize ("use_kwargs" , [True , False ])
1295+ def test_multiple_udf_with_args (self , use_kwargs ):
1296+ # GH#26611
1297+ def func (x , y ):
1298+ return x .sum () + y
1299+
1300+ df = DataFrame ({"A" : [1 , 2 ]})
1301+ expected = DataFrame ({"A" : [13 ]})
1302+ gb = df .groupby ([0 , 0 ])
1303+ if use_kwargs :
1304+ args , kwargs = (), {"y" : 10 }
1305+ else :
1306+ args , kwargs = (10 ,), {}
1307+ result = gb .agg (func , * args , ** kwargs )
1308+ tm .assert_frame_equal (result , expected )
1309+
12651310
12661311def test_pass_args_kwargs_duplicate_columns (tsframe , as_index ):
12671312 # go through _aggregate_frame with self.axis == 0 and duplicate columns
@@ -1383,14 +1428,9 @@ def test_nonagg_agg():
13831428 df = DataFrame ({"a" : [1 , 1 , 2 , 2 ], "b" : [1 , 2 , 2 , 1 ]})
13841429 g = df .groupby ("a" )
13851430
1386- msg = "using the non-aggregation func='cumsum' will raise"
1387- with tm .assert_produces_warning (DeprecationWarning , match = msg ):
1388- result = g .agg (["cumsum" ])
1431+ result = g .agg (["cumsum" ])
13891432 result .columns = result .columns .droplevel (- 1 )
1390-
1391- msg = "using the non-aggregation func='cumsum' will raise"
1392- with tm .assert_produces_warning (DeprecationWarning , match = msg ):
1393- expected = g .agg ("cumsum" )
1433+ expected = g .agg ("cumsum" )
13941434
13951435 tm .assert_frame_equal (result , expected )
13961436
@@ -1467,7 +1507,6 @@ def test_groupby_agg_precision(any_real_numeric_dtype):
14671507 levels = [["a" ], ["b" ]], codes = [[0 ], [0 ]], names = ["key1" , "key2" ]
14681508 ),
14691509 )
1470-
14711510 result = df .groupby (["key1" , "key2" ]).agg (lambda x : x )
14721511 tm .assert_frame_equal (result , expected )
14731512
@@ -1672,9 +1711,7 @@ def test_groupby_agg_extension_timedelta_cumsum_with_named_aggregation():
16721711 }
16731712 )
16741713 gb = df .groupby ("grps" )
1675- msg = "using the non-aggregation func='cumsum' will raise"
1676- with tm .assert_produces_warning (DeprecationWarning , match = msg ):
1677- result = gb .agg (td = ("td" , "cumsum" ))
1714+ result = gb .agg (td = ("td" , "cumsum" ))
16781715 tm .assert_frame_equal (result , expected )
16791716
16801717
0 commit comments