@@ -211,31 +211,26 @@ def test_aggregate_api_consistency():
211211 expected = pd .concat ([c_mean , c_sum , d_mean , d_sum ], axis = 1 )
212212 expected .columns = MultiIndex .from_product ([["C" , "D" ], ["mean" , "sum" ]])
213213
214- with tm .assert_produces_warning (FutureWarning , check_stacklevel = False ):
215- result = grouped [["D" , "C" ]].agg ({"r" : np .sum , "r2" : np .mean })
216- expected = pd .concat ([d_sum , c_sum , d_mean , c_mean ], axis = 1 )
217- expected .columns = MultiIndex .from_product ([["r" , "r2" ], ["D" , "C" ]])
218- tm .assert_frame_equal (result , expected , check_like = True )
214+ msg = r"nested renamer is not supported"
215+ with pytest .raises (SpecificationError , match = msg ):
216+ grouped [["D" , "C" ]].agg ({"r" : np .sum , "r2" : np .mean })
219217
220218
221219def test_agg_dict_renaming_deprecation ():
222220 # 15931
223221 df = pd .DataFrame ({"A" : [1 , 1 , 1 , 2 , 2 ], "B" : range (5 ), "C" : range (5 )})
224222
225- with tm .assert_produces_warning (FutureWarning , check_stacklevel = False ) as w :
223+ msg = r"nested renamer is not supported"
224+ with pytest .raises (SpecificationError , match = msg ):
226225 df .groupby ("A" ).agg (
227226 {"B" : {"foo" : ["sum" , "max" ]}, "C" : {"bar" : ["count" , "min" ]}}
228227 )
229- assert "using a dict with renaming" in str (w [0 ].message )
230- assert "named aggregation" in str (w [0 ].message )
231228
232- with tm . assert_produces_warning ( FutureWarning , check_stacklevel = False ):
229+ with pytest . raises ( SpecificationError , match = msg ):
233230 df .groupby ("A" )[["B" , "C" ]].agg ({"ma" : "max" })
234231
235- with tm . assert_produces_warning ( FutureWarning ) as w :
232+ with pytest . raises ( SpecificationError , match = msg ) :
236233 df .groupby ("A" ).B .agg ({"foo" : "count" })
237- assert "using a dict on a Series for aggregation" in str (w [0 ].message )
238- assert "named aggregation instead." in str (w [0 ].message )
239234
240235
241236def test_agg_compat ():
@@ -251,18 +246,12 @@ def test_agg_compat():
251246
252247 g = df .groupby (["A" , "B" ])
253248
254- expected = pd .concat ([g ["D" ].sum (), g ["D" ].std ()], axis = 1 )
255- expected .columns = MultiIndex .from_tuples ([("C" , "sum" ), ("C" , "std" )])
256- with tm .assert_produces_warning (FutureWarning , check_stacklevel = False ):
257- result = g ["D" ].agg ({"C" : ["sum" , "std" ]})
258- tm .assert_frame_equal (result , expected , check_like = True )
259-
260- expected = pd .concat ([g ["D" ].sum (), g ["D" ].std ()], axis = 1 )
261- expected .columns = ["C" , "D" ]
249+ msg = r"nested renamer is not supported"
250+ with pytest .raises (SpecificationError , match = msg ):
251+ g ["D" ].agg ({"C" : ["sum" , "std" ]})
262252
263- with tm .assert_produces_warning (FutureWarning , check_stacklevel = False ):
264- result = g ["D" ].agg ({"C" : "sum" , "D" : "std" })
265- tm .assert_frame_equal (result , expected , check_like = True )
253+ with pytest .raises (SpecificationError , match = msg ):
254+ g ["D" ].agg ({"C" : "sum" , "D" : "std" })
266255
267256
268257def test_agg_nested_dicts ():
@@ -278,29 +267,20 @@ def test_agg_nested_dicts():
278267
279268 g = df .groupby (["A" , "B" ])
280269
281- msg = r"cannot perform renaming for r[1-2] with a nested dictionary "
270+ msg = r"nested renamer is not supported "
282271 with pytest .raises (SpecificationError , match = msg ):
283272 g .aggregate ({"r1" : {"C" : ["mean" , "sum" ]}, "r2" : {"D" : ["mean" , "sum" ]}})
284273
285- with tm .assert_produces_warning (FutureWarning , check_stacklevel = False ):
286- result = g .agg ({"C" : {"ra" : ["mean" , "std" ]}, "D" : {"rb" : ["mean" , "std" ]}})
287- expected = pd .concat (
288- [g ["C" ].mean (), g ["C" ].std (), g ["D" ].mean (), g ["D" ].std ()], axis = 1
289- )
290- expected .columns = pd .MultiIndex .from_tuples (
291- [("ra" , "mean" ), ("ra" , "std" ), ("rb" , "mean" ), ("rb" , "std" )]
292- )
293- tm .assert_frame_equal (result , expected , check_like = True )
274+ with pytest .raises (SpecificationError , match = msg ):
275+ g .agg ({"C" : {"ra" : ["mean" , "std" ]}, "D" : {"rb" : ["mean" , "std" ]}})
294276
295277 # same name as the original column
296278 # GH9052
297- with tm .assert_produces_warning (FutureWarning , check_stacklevel = False ):
298- expected = g ["D" ].agg ({"result1" : np .sum , "result2" : np .mean })
299- expected = expected .rename (columns = {"result1" : "D" })
279+ with pytest .raises (SpecificationError , match = msg ):
280+ g ["D" ].agg ({"result1" : np .sum , "result2" : np .mean })
300281
301- with tm .assert_produces_warning (FutureWarning , check_stacklevel = False ):
302- result = g ["D" ].agg ({"D" : np .sum , "result2" : np .mean })
303- tm .assert_frame_equal (result , expected , check_like = True )
282+ with pytest .raises (SpecificationError , match = msg ):
283+ g ["D" ].agg ({"D" : np .sum , "result2" : np .mean })
304284
305285
306286def test_agg_item_by_item_raise_typeerror ():
0 commit comments