diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 04ff8ec9f430d..890cd30f9fe8e 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -11430,6 +11430,7 @@ def corr( dogs 1.0 NaN cats NaN 1.0 """ # noqa: E501 + validate_bool_kwarg(numeric_only, "numeric_only") data = self._get_numeric_data() if numeric_only else self cols = data.columns idx = cols.copy() @@ -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 = ( @@ -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 @@ -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: @@ -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) @@ -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) @@ -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) @@ -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) @@ -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]): @@ -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]): @@ -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): @@ -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 diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 93a7de467dd97..41a4ad68085b3 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -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'" @@ -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 @@ -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 @@ -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 @@ -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, diff --git a/pandas/core/groupby/generic.py b/pandas/core/groupby/generic.py index 39607d74c0dc8..b1cfb1d71b2e3 100644 --- a/pandas/core/groupby/generic.py +++ b/pandas/core/groupby/generic.py @@ -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, @@ -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): @@ -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: @@ -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 ) @@ -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: diff --git a/pandas/core/groupby/groupby.py b/pandas/core/groupby/groupby.py index f9789c82a1536..86feed4fa0f4b 100644 --- a/pandas/core/groupby/groupby.py +++ b/pandas/core/groupby/groupby.py @@ -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, @@ -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 ):