@@ -211,31 +211,26 @@ def test_aggregate_api_consistency():
211
211
expected = pd .concat ([c_mean , c_sum , d_mean , d_sum ], axis = 1 )
212
212
expected .columns = MultiIndex .from_product ([["C" , "D" ], ["mean" , "sum" ]])
213
213
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 })
219
217
220
218
221
219
def test_agg_dict_renaming_deprecation ():
222
220
# 15931
223
221
df = pd .DataFrame ({"A" : [1 , 1 , 1 , 2 , 2 ], "B" : range (5 ), "C" : range (5 )})
224
222
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 ):
226
225
df .groupby ("A" ).agg (
227
226
{"B" : {"foo" : ["sum" , "max" ]}, "C" : {"bar" : ["count" , "min" ]}}
228
227
)
229
- assert "using a dict with renaming" in str (w [0 ].message )
230
- assert "named aggregation" in str (w [0 ].message )
231
228
232
- with tm . assert_produces_warning ( FutureWarning , check_stacklevel = False ):
229
+ with pytest . raises ( SpecificationError , match = msg ):
233
230
df .groupby ("A" )[["B" , "C" ]].agg ({"ma" : "max" })
234
231
235
- with tm . assert_produces_warning ( FutureWarning ) as w :
232
+ with pytest . raises ( SpecificationError , match = msg ) :
236
233
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 )
239
234
240
235
241
236
def test_agg_compat ():
@@ -251,18 +246,12 @@ def test_agg_compat():
251
246
252
247
g = df .groupby (["A" , "B" ])
253
248
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" ]})
262
252
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" })
266
255
267
256
268
257
def test_agg_nested_dicts ():
@@ -278,29 +267,20 @@ def test_agg_nested_dicts():
278
267
279
268
g = df .groupby (["A" , "B" ])
280
269
281
- msg = r"cannot perform renaming for r[1-2] with a nested dictionary "
270
+ msg = r"nested renamer is not supported "
282
271
with pytest .raises (SpecificationError , match = msg ):
283
272
g .aggregate ({"r1" : {"C" : ["mean" , "sum" ]}, "r2" : {"D" : ["mean" , "sum" ]}})
284
273
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" ]}})
294
276
295
277
# same name as the original column
296
278
# 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 })
300
281
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 })
304
284
305
285
306
286
def test_agg_item_by_item_raise_typeerror ():
0 commit comments