@@ -87,13 +87,15 @@ def test_max_min_object_multiple_columns(using_array_manager):
87
87
88
88
gb = df .groupby ("A" )
89
89
90
- result = gb .max (numeric_only = False )
90
+ with tm .assert_produces_warning (FutureWarning , match = "Dropping invalid" ):
91
+ result = gb .max (numeric_only = False )
91
92
# "max" is valid for column "C" but not for "B"
92
93
ei = Index ([1 , 2 , 3 ], name = "A" )
93
94
expected = DataFrame ({"C" : ["b" , "d" , "e" ]}, index = ei )
94
95
tm .assert_frame_equal (result , expected )
95
96
96
- result = gb .min (numeric_only = False )
97
+ with tm .assert_produces_warning (FutureWarning , match = "Dropping invalid" ):
98
+ result = gb .min (numeric_only = False )
97
99
# "min" is valid for column "C" but not for "B"
98
100
ei = Index ([1 , 2 , 3 ], name = "A" )
99
101
expected = DataFrame ({"C" : ["a" , "c" , "e" ]}, index = ei )
@@ -221,7 +223,10 @@ def test_averages(self, df, method):
221
223
],
222
224
)
223
225
224
- result = getattr (gb , method )(numeric_only = False )
226
+ with tm .assert_produces_warning (
227
+ FutureWarning , match = "Dropping invalid" , check_stacklevel = False
228
+ ):
229
+ result = getattr (gb , method )(numeric_only = False )
225
230
tm .assert_frame_equal (result .reindex_like (expected ), expected )
226
231
227
232
expected_columns = expected .columns
@@ -303,10 +308,27 @@ def test_cummin_cummax(self, df, method):
303
308
def _check (self , df , method , expected_columns , expected_columns_numeric ):
304
309
gb = df .groupby ("group" )
305
310
306
- result = getattr (gb , method )()
311
+ # cummin, cummax dont have numeric_only kwarg, always use False
312
+ warn = None
313
+ if method in ["cummin" , "cummax" ]:
314
+ # these dont have numeric_only kwarg, always use False
315
+ warn = FutureWarning
316
+ elif method in ["min" , "max" ]:
317
+ # these have numeric_only kwarg, but default to False
318
+ warn = FutureWarning
319
+
320
+ with tm .assert_produces_warning (warn , match = "Dropping invalid columns" ):
321
+ result = getattr (gb , method )()
322
+
307
323
tm .assert_index_equal (result .columns , expected_columns_numeric )
308
324
309
- result = getattr (gb , method )(numeric_only = False )
325
+ # GH#41475 deprecated silently ignoring nuisance columns
326
+ warn = None
327
+ if len (expected_columns ) < len (gb ._obj_with_exclusions .columns ):
328
+ warn = FutureWarning
329
+ with tm .assert_produces_warning (warn , match = "Dropping invalid columns" ):
330
+ result = getattr (gb , method )(numeric_only = False )
331
+
310
332
tm .assert_index_equal (result .columns , expected_columns )
311
333
312
334
0 commit comments