Skip to content

Commit 48e7b6e

Browse files
authored
DEPR: Change numeric_only default to False in remaining groupby methods (#49951)
* DEPR: Change numeric_only default to False in remaining groupby methods * More cleanup of ignore_failures
1 parent 32b4222 commit 48e7b6e

File tree

15 files changed

+158
-419
lines changed

15 files changed

+158
-419
lines changed

doc/source/whatsnew/v2.0.0.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,7 @@ Removal of prior version deprecations/changes
572572
- Changed default of ``numeric_only`` to ``False`` in all DataFrame methods with that argument (:issue:`46096`, :issue:`46906`)
573573
- Changed default of ``numeric_only`` to ``False`` in :meth:`Series.rank` (:issue:`47561`)
574574
- Enforced deprecation of silently dropping nuisance columns in groupby and resample operations when ``numeric_only=False`` (:issue:`41475`)
575-
- Changed default of ``numeric_only`` to ``False`` in various :class:`.DataFrameGroupBy` methods (:issue:`46072`)
575+
- Changed default of ``numeric_only`` in various :class:`.DataFrameGroupBy` methods; all methods now default to ``numeric_only=False`` (:issue:`46072`)
576576
- Changed default of ``numeric_only`` to ``False`` in :class:`.Resampler` methods (:issue:`47177`)
577577
-
578578

pandas/core/groupby/generic.py

+9-22
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@
8787
_agg_template,
8888
_apply_docs,
8989
_transform_template,
90-
warn_dropping_nuisance_columns_deprecated,
9190
)
9291
from pandas.core.groupby.grouper import get_grouper
9392
from pandas.core.indexes.api import (
@@ -438,7 +437,7 @@ def transform(self, func, *args, engine=None, engine_kwargs=None, **kwargs):
438437
)
439438

440439
def _cython_transform(
441-
self, how: str, numeric_only: bool = True, axis: AxisInt = 0, **kwargs
440+
self, how: str, numeric_only: bool = False, axis: AxisInt = 0, **kwargs
442441
):
443442
assert axis == 0 # handled by caller
444443

@@ -1333,22 +1332,20 @@ def _wrap_applied_output_series(
13331332
def _cython_transform(
13341333
self,
13351334
how: str,
1336-
numeric_only: bool | lib.NoDefault = lib.no_default,
1335+
numeric_only: bool = False,
13371336
axis: AxisInt = 0,
13381337
**kwargs,
13391338
) -> DataFrame:
13401339
assert axis == 0 # handled by caller
13411340
# TODO: no tests with self.ndim == 1 for DataFrameGroupBy
1342-
numeric_only_bool = self._resolve_numeric_only(how, numeric_only, axis)
13431341

13441342
# With self.axis == 0, we have multi-block tests
13451343
# e.g. test_rank_min_int, test_cython_transform_frame
13461344
# test_transform_numeric_ret
13471345
# With self.axis == 1, _get_data_to_aggregate does a transpose
13481346
# so we always have a single block.
13491347
mgr: Manager2D = self._get_data_to_aggregate()
1350-
orig_mgr_len = len(mgr)
1351-
if numeric_only_bool:
1348+
if numeric_only:
13521349
mgr = mgr.get_numeric_data(copy=False)
13531350

13541351
def arr_func(bvalues: ArrayLike) -> ArrayLike:
@@ -1358,12 +1355,9 @@ def arr_func(bvalues: ArrayLike) -> ArrayLike:
13581355

13591356
# We could use `mgr.apply` here and not have to set_axis, but
13601357
# we would have to do shape gymnastics for ArrayManager compat
1361-
res_mgr = mgr.grouped_reduce(arr_func, ignore_failures=False)
1358+
res_mgr = mgr.grouped_reduce(arr_func)
13621359
res_mgr.set_axis(1, mgr.axes[1])
13631360

1364-
if len(res_mgr) < orig_mgr_len:
1365-
warn_dropping_nuisance_columns_deprecated(type(self), how, numeric_only)
1366-
13671361
res_df = self.obj._constructor(res_mgr)
13681362
if self.axis == 1:
13691363
res_df = res_df.T
@@ -1493,15 +1487,8 @@ def _transform_item_by_item(self, obj: DataFrame, wrapper) -> DataFrame:
14931487
output = {}
14941488
inds = []
14951489
for i, (colname, sgb) in enumerate(self._iterate_column_groupbys(obj)):
1496-
try:
1497-
output[i] = sgb.transform(wrapper)
1498-
except TypeError:
1499-
# e.g. trying to call nanmean with string values
1500-
warn_dropping_nuisance_columns_deprecated(
1501-
type(self), "transform", numeric_only=False
1502-
)
1503-
else:
1504-
inds.append(i)
1490+
output[i] = sgb.transform(wrapper)
1491+
inds.append(i)
15051492

15061493
if not output:
15071494
raise TypeError("Transform function invalid for data types")
@@ -2243,7 +2230,7 @@ def corr(
22432230
self,
22442231
method: str | Callable[[np.ndarray, np.ndarray], float] = "pearson",
22452232
min_periods: int = 1,
2246-
numeric_only: bool | lib.NoDefault = lib.no_default,
2233+
numeric_only: bool = False,
22472234
) -> DataFrame:
22482235
result = self._op_via_apply(
22492236
"corr", method=method, min_periods=min_periods, numeric_only=numeric_only
@@ -2255,7 +2242,7 @@ def cov(
22552242
self,
22562243
min_periods: int | None = None,
22572244
ddof: int | None = 1,
2258-
numeric_only: bool | lib.NoDefault = lib.no_default,
2245+
numeric_only: bool = False,
22592246
) -> DataFrame:
22602247
result = self._op_via_apply(
22612248
"cov", min_periods=min_periods, ddof=ddof, numeric_only=numeric_only
@@ -2316,7 +2303,7 @@ def corrwith(
23162303
axis: Axis = 0,
23172304
drop: bool = False,
23182305
method: CorrelationMethod = "pearson",
2319-
numeric_only: bool | lib.NoDefault = lib.no_default,
2306+
numeric_only: bool = False,
23202307
) -> DataFrame:
23212308
result = self._op_via_apply(
23222309
"corrwith",

0 commit comments

Comments
 (0)