Skip to content

Commit 9a9898a

Browse files
committed
BUG: validate_bool_kwarg for numeric_only
1 parent 7f670c1 commit 9a9898a

File tree

4 files changed

+26
-0
lines changed

4 files changed

+26
-0
lines changed

pandas/core/frame.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11430,6 +11430,7 @@ def corr(
1143011430
dogs 1.0 NaN
1143111431
cats NaN 1.0
1143211432
""" # noqa: E501
11433+
validate_bool_kwarg(numeric_only, "numeric_only")
1143311434
data = self._get_numeric_data() if numeric_only else self
1143411435
cols = data.columns
1143511436
idx = cols.copy()
@@ -11586,6 +11587,7 @@ def cov(
1158611587
b NaN 1.248003 0.191417
1158711588
c -0.150812 0.191417 0.895202
1158811589
"""
11590+
validate_bool_kwarg(numeric_only, "numeric_only")
1158911591
data = self._get_numeric_data() if numeric_only else self
1159011592
if any(blk.dtype.kind in "mM" for blk in self._mgr.blocks):
1159111593
msg = (
@@ -11690,6 +11692,7 @@ def corrwith(
1169011692
e NaN
1169111693
dtype: float64
1169211694
"""
11695+
validate_bool_kwarg(numeric_only, "numeric_only")
1169311696
axis = self._get_axis_number(axis)
1169411697
this = self._get_numeric_data() if numeric_only else self
1169511698

@@ -11825,6 +11828,7 @@ def count(self, axis: Axis = 0, numeric_only: bool = False) -> Series:
1182511828
4 3
1182611829
dtype: int64
1182711830
"""
11831+
validate_bool_kwarg(numeric_only, "numeric_only")
1182811832
axis = self._get_axis_number(axis)
1182911833

1183011834
if numeric_only:
@@ -13073,6 +13077,7 @@ def cummin(
1307313077
*args,
1307413078
**kwargs,
1307513079
) -> Self:
13080+
validate_bool_kwarg(numeric_only, "numeric_only")
1307613081
data = self._get_numeric_data() if numeric_only else self
1307713082
return NDFrame.cummin(data, axis, skipna, *args, **kwargs)
1307813083

@@ -13085,6 +13090,7 @@ def cummax(
1308513090
*args,
1308613091
**kwargs,
1308713092
) -> Self:
13093+
validate_bool_kwarg(numeric_only, "numeric_only")
1308813094
data = self._get_numeric_data() if numeric_only else self
1308913095
return NDFrame.cummax(data, axis, skipna, *args, **kwargs)
1309013096

@@ -13097,6 +13103,7 @@ def cumsum(
1309713103
*args,
1309813104
**kwargs,
1309913105
) -> Self:
13106+
validate_bool_kwarg(numeric_only, "numeric_only")
1310013107
data = self._get_numeric_data() if numeric_only else self
1310113108
return NDFrame.cumsum(data, axis, skipna, *args, **kwargs)
1310213109

@@ -13109,6 +13116,7 @@ def cumprod(
1310913116
*args,
1311013117
**kwargs,
1311113118
) -> Self:
13119+
validate_bool_kwarg(numeric_only, "numeric_only")
1311213120
data = self._get_numeric_data() if numeric_only else self
1311313121
return NDFrame.cumprod(data, axis, skipna, *args, **kwargs)
1311413122

@@ -13227,6 +13235,7 @@ def idxmin(
1322713235
Beef consumption
1322813236
dtype: object
1322913237
"""
13238+
validate_bool_kwarg(numeric_only, "numeric_only")
1323013239
axis = self._get_axis_number(axis)
1323113240

1323213241
if self.empty and len(self.axes[axis]):
@@ -13332,6 +13341,7 @@ def idxmax(
1333213341
Beef co2_emissions
1333313342
dtype: object
1333413343
"""
13344+
validate_bool_kwarg(numeric_only, "numeric_only")
1333513345
axis = self._get_axis_number(axis)
1333613346

1333713347
if self.empty and len(self.axes[axis]):
@@ -13458,6 +13468,7 @@ def mode(
1345813468
spider 0.0 8.0
1345913469
ostrich 2.0 NaN
1346013470
"""
13471+
validate_bool_kwarg(numeric_only, "numeric_only")
1346113472
data = self if not numeric_only else self._get_numeric_data()
1346213473

1346313474
def f(s):
@@ -13596,6 +13607,7 @@ def quantile(
1359613607
"""
1359713608
validate_percentile(q)
1359813609
axis = self._get_axis_number(axis)
13610+
validate_bool_kwarg(numeric_only, "numeric_only")
1359913611

1360013612
if not is_list_like(q):
1360113613
# BlockManager.quantile expects listlike, so we wrap and unwrap here

pandas/core/generic.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9271,6 +9271,7 @@ def rank(
92719271
4 snake NaN NaN NaN 5.0 NaN
92729272
"""
92739273
axis_int = self._get_axis_number(axis)
9274+
validate_bool_kwarg(numeric_only, "numeric_only")
92749275

92759276
if na_option not in {"keep", "top", "bottom"}:
92769277
msg = "na_option must be one of 'keep', 'top', or 'bottom'"
@@ -11282,6 +11283,7 @@ def _logical_func(
1128211283
) -> Series | bool:
1128311284
nv.validate_logical_func((), kwargs, fname=name)
1128411285
validate_bool_kwarg(skipna, "skipna", none_allowed=False)
11286+
validate_bool_kwarg(bool_only, "bool_only")
1128511287

1128611288
if self.ndim > 1 and axis is None:
1128711289
# Reduce along one dimension then the other, to simplify DataFrame._reduce
@@ -11415,6 +11417,7 @@ def _stat_function_ddof(
1141511417
) -> Series | float:
1141611418
nv.validate_stat_ddof_func((), kwargs, fname=name)
1141711419
validate_bool_kwarg(skipna, "skipna", none_allowed=False)
11420+
validate_bool_kwarg(numeric_only, "numeric_only")
1141811421

1141911422
return self._reduce(
1142011423
func, name, axis=axis, numeric_only=numeric_only, skipna=skipna, ddof=ddof
@@ -11473,6 +11476,7 @@ def _stat_function(
1147311476
nv.validate_func(name, (), kwargs)
1147411477

1147511478
validate_bool_kwarg(skipna, "skipna", none_allowed=False)
11479+
validate_bool_kwarg(numeric_only, "numeric_only")
1147611480

1147711481
return self._reduce(
1147811482
func, name=name, axis=axis, skipna=skipna, numeric_only=numeric_only
@@ -11577,6 +11581,7 @@ def _min_count_stat_function(
1157711581
nv.validate_func(name, (), kwargs)
1157811582

1157911583
validate_bool_kwarg(skipna, "skipna", none_allowed=False)
11584+
validate_bool_kwarg(numeric_only, "numeric_only")
1158011585

1158111586
return self._reduce(
1158211587
func,

pandas/core/groupby/generic.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
set_module,
3939
)
4040
from pandas.util._exceptions import find_stack_level
41+
from pandas.util._validators import validate_bool_kwarg
4142

4243
from pandas.core.dtypes.common import (
4344
ensure_int64,
@@ -157,6 +158,8 @@ def _wrap_agged_manager(self, mgr: Manager) -> Series:
157158
def _get_data_to_aggregate(
158159
self, *, numeric_only: bool = False, name: str | None = None
159160
) -> SingleBlockManager:
161+
validate_bool_kwarg(numeric_only, "numeric_only")
162+
160163
ser = self._obj_with_exclusions
161164
single = ser._mgr
162165
if numeric_only and not is_numeric_dtype(ser.dtype):
@@ -683,6 +686,7 @@ def transform(self, func, *args, engine=None, engine_kwargs=None, **kwargs):
683686
)
684687

685688
def _cython_transform(self, how: str, numeric_only: bool = False, **kwargs):
689+
validate_bool_kwarg(numeric_only, "numeric_only")
686690
obj = self._obj_with_exclusions
687691

688692
try:
@@ -2180,6 +2184,8 @@ def _cython_transform(
21802184
# We have multi-block tests
21812185
# e.g. test_rank_min_int, test_cython_transform_frame
21822186
# test_transform_numeric_ret
2187+
validate_bool_kwarg(numeric_only, "numeric_only")
2188+
21832189
mgr: BlockManager = self._get_data_to_aggregate(
21842190
numeric_only=numeric_only, name=how
21852191
)
@@ -2500,6 +2506,7 @@ def _gotitem(self, key, ndim: int, subset=None):
25002506
def _get_data_to_aggregate(
25012507
self, *, numeric_only: bool = False, name: str | None = None
25022508
) -> BlockManager:
2509+
validate_bool_kwarg(numeric_only, "numeric_only")
25032510
obj = self._obj_with_exclusions
25042511
mgr = obj._mgr
25052512
if numeric_only:

pandas/core/groupby/groupby.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ class providing the base-class of operations.
7070
doc,
7171
)
7272
from pandas.util._exceptions import find_stack_level
73+
from pandas.util._validators import validate_bool_kwarg
7374

7475
from pandas.core.dtypes.cast import (
7576
coerce_indexer_dtype,
@@ -5676,6 +5677,7 @@ def _idxmax_idxmin(
56765677
Series or DataFrame
56775678
idxmax or idxmin for the groupby operation.
56785679
"""
5680+
validate_bool_kwarg(numeric_only, "numeric_only")
56795681
if not self.observed and any(
56805682
ping._passed_categorical for ping in self._grouper.groupings
56815683
):

0 commit comments

Comments
 (0)