@@ -163,14 +163,12 @@ def test_averages(self, df, method):
163
163
"int" ,
164
164
"float" ,
165
165
"category_int" ,
166
- "datetime" ,
167
- "datetimetz" ,
168
- "timedelta" ,
169
166
],
170
167
)
171
168
172
- with tm .assert_produces_warning (FutureWarning , match = "Dropping invalid" ):
173
- result = getattr (gb , method )(numeric_only = False )
169
+ with pytest .raises (TypeError , match = "[Cc]ould not convert" ):
170
+ getattr (gb , method )(numeric_only = False )
171
+ result = getattr (gb , method )()
174
172
tm .assert_frame_equal (result .reindex_like (expected ), expected )
175
173
176
174
expected_columns = expected .columns
@@ -252,30 +250,35 @@ def test_cummin_cummax(self, df, method):
252
250
def _check (self , df , method , expected_columns , expected_columns_numeric ):
253
251
gb = df .groupby ("group" )
254
252
255
- # cummin, cummax dont have numeric_only kwarg, always use False
256
- warn = None
257
- if method in ["cummin" , "cummax" ]:
258
- # these dont have numeric_only kwarg, always use False
259
- warn = FutureWarning
260
- elif method in ["min" , "max" ]:
261
- # these have numeric_only kwarg, but default to False
262
- warn = FutureWarning
263
-
264
- with tm .assert_produces_warning (
265
- warn , match = "Dropping invalid columns" , raise_on_extra_warnings = False
266
- ):
253
+ if method in ("min" , "max" , "cummin" , "cummax" ):
254
+ # The methods default to numeric_only=False and raise TypeError
255
+ msg = "|" .join (
256
+ [
257
+ "Categorical is not ordered" ,
258
+ "function is not implemented for this dtype" ,
259
+ ]
260
+ )
261
+ with pytest .raises (TypeError , match = msg ):
262
+ getattr (gb , method )()
263
+ else :
267
264
result = getattr (gb , method )()
268
-
269
- tm .assert_index_equal (result .columns , expected_columns_numeric )
270
-
271
- # GH#41475 deprecated silently ignoring nuisance columns
272
- warn = None
273
- if len (expected_columns ) < len (gb ._obj_with_exclusions .columns ):
274
- warn = FutureWarning
275
- with tm .assert_produces_warning (warn , match = "Dropping invalid columns" ):
265
+ tm .assert_index_equal (result .columns , expected_columns_numeric )
266
+
267
+ if method not in ("first" , "last" ):
268
+ msg = "|" .join (
269
+ [
270
+ "[Cc]ould not convert" ,
271
+ "Categorical is not ordered" ,
272
+ "category type does not support" ,
273
+ "can't multiply sequence" ,
274
+ "function is not implemented for this dtype" ,
275
+ ]
276
+ )
277
+ with pytest .raises (TypeError , match = msg ):
278
+ getattr (gb , method )(numeric_only = False )
279
+ else :
276
280
result = getattr (gb , method )(numeric_only = False )
277
-
278
- tm .assert_index_equal (result .columns , expected_columns )
281
+ tm .assert_index_equal (result .columns , expected_columns )
279
282
280
283
281
284
class TestGroupByNonCythonPaths :
@@ -1323,45 +1326,45 @@ def test_groupby_sum_timedelta_with_nat():
1323
1326
1324
1327
1325
1328
@pytest .mark .parametrize (
1326
- "kernel, numeric_only_default, drops_nuisance, has_arg" ,
1329
+ "kernel, numeric_only_default, has_arg" ,
1327
1330
[
1328
- ("all" , False , False , False ),
1329
- ("any" , False , False , False ),
1330
- ("bfill" , False , False , False ),
1331
- ("corr" , True , False , True ),
1332
- ("corrwith" , True , False , True ),
1333
- ("cov" , True , False , True ),
1334
- ("cummax" , False , True , True ),
1335
- ("cummin" , False , True , True ),
1336
- ("cumprod" , True , True , True ),
1337
- ("cumsum" , True , True , True ),
1338
- ("diff" , False , False , False ),
1339
- ("ffill" , False , False , False ),
1340
- ("fillna" , False , False , False ),
1341
- ("first" , False , False , True ),
1342
- ("idxmax" , True , False , True ),
1343
- ("idxmin" , True , False , True ),
1344
- ("last" , False , False , True ),
1345
- ("max" , False , True , True ),
1346
- ("mean" , True , True , True ),
1347
- ("median" , True , True , True ),
1348
- ("min" , False , True , True ),
1349
- ("nth" , False , False , False ),
1350
- ("nunique" , False , False , False ),
1351
- ("pct_change" , False , False , False ),
1352
- ("prod" , True , True , True ),
1353
- ("quantile" , True , False , True ),
1354
- ("sem" , True , True , True ),
1355
- ("skew" , True , False , True ),
1356
- ("std" , True , True , True ),
1357
- ("sum" , True , True , True ),
1358
- ("var" , True , False , True ),
1331
+ ("all" , False , False ),
1332
+ ("any" , False , False ),
1333
+ ("bfill" , False , False ),
1334
+ ("corr" , True , True ),
1335
+ ("corrwith" , True , True ),
1336
+ ("cov" , True , True ),
1337
+ ("cummax" , False , True ),
1338
+ ("cummin" , False , True ),
1339
+ ("cumprod" , True , True ),
1340
+ ("cumsum" , True , True ),
1341
+ ("diff" , False , False ),
1342
+ ("ffill" , False , False ),
1343
+ ("fillna" , False , False ),
1344
+ ("first" , False , True ),
1345
+ ("idxmax" , True , True ),
1346
+ ("idxmin" , True , True ),
1347
+ ("last" , False , True ),
1348
+ ("max" , False , True ),
1349
+ ("mean" , True , True ),
1350
+ ("median" , True , True ),
1351
+ ("min" , False , True ),
1352
+ ("nth" , False , False ),
1353
+ ("nunique" , False , False ),
1354
+ ("pct_change" , False , False ),
1355
+ ("prod" , True , True ),
1356
+ ("quantile" , True , True ),
1357
+ ("sem" , True , True ),
1358
+ ("skew" , True , True ),
1359
+ ("std" , True , True ),
1360
+ ("sum" , True , True ),
1361
+ ("var" , True , True ),
1359
1362
],
1360
1363
)
1361
1364
@pytest .mark .parametrize ("numeric_only" , [True , False , lib .no_default ])
1362
1365
@pytest .mark .parametrize ("keys" , [["a1" ], ["a1" , "a2" ]])
1363
1366
def test_deprecate_numeric_only (
1364
- kernel , numeric_only_default , drops_nuisance , has_arg , numeric_only , keys
1367
+ kernel , numeric_only_default , has_arg , numeric_only , keys
1365
1368
):
1366
1369
# GH#46072
1367
1370
# drops_nuisance: Whether the op drops nuisance columns even when numeric_only=False
@@ -1380,10 +1383,9 @@ def test_deprecate_numeric_only(
1380
1383
# Cases where b does not appear in the result
1381
1384
numeric_only is True
1382
1385
or (numeric_only is lib .no_default and numeric_only_default )
1383
- or drops_nuisance
1384
1386
)
1385
1387
):
1386
- if numeric_only is True or ( not numeric_only_default and not drops_nuisance ) :
1388
+ if numeric_only is True or not numeric_only_default :
1387
1389
warn = None
1388
1390
else :
1389
1391
warn = FutureWarning
@@ -1408,14 +1410,17 @@ def test_deprecate_numeric_only(
1408
1410
assert "b" in result .columns
1409
1411
elif has_arg or kernel in ("idxmax" , "idxmin" ):
1410
1412
assert numeric_only is not True
1411
- assert not drops_nuisance
1412
1413
# kernels that are successful on any dtype were above; this will fail
1413
- msg = (
1414
- "(not allowed for this dtype"
1415
- "|must be a string or a number"
1416
- "|cannot be performed against 'object' dtypes"
1417
- "|must be a string or a real number"
1418
- "|unsupported operand type)"
1414
+ msg = "|" .join (
1415
+ [
1416
+ "not allowed for this dtype" ,
1417
+ "must be a string or a number" ,
1418
+ "cannot be performed against 'object' dtypes" ,
1419
+ "must be a string or a real number" ,
1420
+ "unsupported operand type" ,
1421
+ "not supported between instances of" ,
1422
+ "function is not implemented for this dtype" ,
1423
+ ]
1419
1424
)
1420
1425
with pytest .raises (TypeError , match = msg ):
1421
1426
method (* args , ** kwargs )
0 commit comments