Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -11430,6 +11430,7 @@ def corr(
dogs 1.0 NaN
cats NaN 1.0
""" # noqa: E501
validate_bool_kwarg(numeric_only, "numeric_only")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think none_allowed=False needs to be passed to all these calls (and none_allowed=True shouldn't probably be the default for this function)

data = self._get_numeric_data() if numeric_only else self
cols = data.columns
idx = cols.copy()
Expand Down Expand Up @@ -11586,6 +11587,7 @@ def cov(
b NaN 1.248003 0.191417
c -0.150812 0.191417 0.895202
"""
validate_bool_kwarg(numeric_only, "numeric_only")
data = self._get_numeric_data() if numeric_only else self
if any(blk.dtype.kind in "mM" for blk in self._mgr.blocks):
msg = (
Expand Down Expand Up @@ -11690,6 +11692,7 @@ def corrwith(
e NaN
dtype: float64
"""
validate_bool_kwarg(numeric_only, "numeric_only")
axis = self._get_axis_number(axis)
this = self._get_numeric_data() if numeric_only else self

Expand Down Expand Up @@ -11825,6 +11828,7 @@ def count(self, axis: Axis = 0, numeric_only: bool = False) -> Series:
4 3
dtype: int64
"""
validate_bool_kwarg(numeric_only, "numeric_only")
axis = self._get_axis_number(axis)

if numeric_only:
Expand Down Expand Up @@ -13073,6 +13077,7 @@ def cummin(
*args,
**kwargs,
) -> Self:
validate_bool_kwarg(numeric_only, "numeric_only")
data = self._get_numeric_data() if numeric_only else self
return NDFrame.cummin(data, axis, skipna, *args, **kwargs)

Expand All @@ -13085,6 +13090,7 @@ def cummax(
*args,
**kwargs,
) -> Self:
validate_bool_kwarg(numeric_only, "numeric_only")
data = self._get_numeric_data() if numeric_only else self
return NDFrame.cummax(data, axis, skipna, *args, **kwargs)

Expand All @@ -13097,6 +13103,7 @@ def cumsum(
*args,
**kwargs,
) -> Self:
validate_bool_kwarg(numeric_only, "numeric_only")
data = self._get_numeric_data() if numeric_only else self
return NDFrame.cumsum(data, axis, skipna, *args, **kwargs)

Expand All @@ -13109,6 +13116,7 @@ def cumprod(
*args,
**kwargs,
) -> Self:
validate_bool_kwarg(numeric_only, "numeric_only")
data = self._get_numeric_data() if numeric_only else self
return NDFrame.cumprod(data, axis, skipna, *args, **kwargs)

Expand Down Expand Up @@ -13227,6 +13235,7 @@ def idxmin(
Beef consumption
dtype: object
"""
validate_bool_kwarg(numeric_only, "numeric_only")
axis = self._get_axis_number(axis)

if self.empty and len(self.axes[axis]):
Expand Down Expand Up @@ -13332,6 +13341,7 @@ def idxmax(
Beef co2_emissions
dtype: object
"""
validate_bool_kwarg(numeric_only, "numeric_only")
axis = self._get_axis_number(axis)

if self.empty and len(self.axes[axis]):
Expand Down Expand Up @@ -13458,6 +13468,7 @@ def mode(
spider 0.0 8.0
ostrich 2.0 NaN
"""
validate_bool_kwarg(numeric_only, "numeric_only")
data = self if not numeric_only else self._get_numeric_data()

def f(s):
Expand Down Expand Up @@ -13596,6 +13607,7 @@ def quantile(
"""
validate_percentile(q)
axis = self._get_axis_number(axis)
validate_bool_kwarg(numeric_only, "numeric_only")

if not is_list_like(q):
# BlockManager.quantile expects listlike, so we wrap and unwrap here
Expand Down
5 changes: 5 additions & 0 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -9271,6 +9271,7 @@ def rank(
4 snake NaN NaN NaN 5.0 NaN
"""
axis_int = self._get_axis_number(axis)
validate_bool_kwarg(numeric_only, "numeric_only")

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

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

return self._reduce(
func, name, axis=axis, numeric_only=numeric_only, skipna=skipna, ddof=ddof
Expand Down Expand Up @@ -11473,6 +11476,7 @@ def _stat_function(
nv.validate_func(name, (), kwargs)

validate_bool_kwarg(skipna, "skipna", none_allowed=False)
validate_bool_kwarg(numeric_only, "numeric_only")

return self._reduce(
func, name=name, axis=axis, skipna=skipna, numeric_only=numeric_only
Expand Down Expand Up @@ -11577,6 +11581,7 @@ def _min_count_stat_function(
nv.validate_func(name, (), kwargs)

validate_bool_kwarg(skipna, "skipna", none_allowed=False)
validate_bool_kwarg(numeric_only, "numeric_only")

return self._reduce(
func,
Expand Down
7 changes: 7 additions & 0 deletions pandas/core/groupby/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
set_module,
)
from pandas.util._exceptions import find_stack_level
from pandas.util._validators import validate_bool_kwarg

from pandas.core.dtypes.common import (
ensure_int64,
Expand Down Expand Up @@ -157,6 +158,8 @@ def _wrap_agged_manager(self, mgr: Manager) -> Series:
def _get_data_to_aggregate(
self, *, numeric_only: bool = False, name: str | None = None
) -> SingleBlockManager:
validate_bool_kwarg(numeric_only, "numeric_only")

ser = self._obj_with_exclusions
single = ser._mgr
if numeric_only and not is_numeric_dtype(ser.dtype):
Expand Down Expand Up @@ -683,6 +686,7 @@ def transform(self, func, *args, engine=None, engine_kwargs=None, **kwargs):
)

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

try:
Expand Down Expand Up @@ -2180,6 +2184,8 @@ def _cython_transform(
# We have multi-block tests
# e.g. test_rank_min_int, test_cython_transform_frame
# test_transform_numeric_ret
validate_bool_kwarg(numeric_only, "numeric_only")

mgr: BlockManager = self._get_data_to_aggregate(
numeric_only=numeric_only, name=how
)
Expand Down Expand Up @@ -2500,6 +2506,7 @@ def _gotitem(self, key, ndim: int, subset=None):
def _get_data_to_aggregate(
self, *, numeric_only: bool = False, name: str | None = None
) -> BlockManager:
validate_bool_kwarg(numeric_only, "numeric_only")
obj = self._obj_with_exclusions
mgr = obj._mgr
if numeric_only:
Expand Down
2 changes: 2 additions & 0 deletions pandas/core/groupby/groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ class providing the base-class of operations.
doc,
)
from pandas.util._exceptions import find_stack_level
from pandas.util._validators import validate_bool_kwarg

from pandas.core.dtypes.cast import (
coerce_indexer_dtype,
Expand Down Expand Up @@ -5676,6 +5677,7 @@ def _idxmax_idxmin(
Series or DataFrame
idxmax or idxmin for the groupby operation.
"""
validate_bool_kwarg(numeric_only, "numeric_only")
if not self.observed and any(
ping._passed_categorical for ping in self._grouper.groupings
):
Expand Down
Loading