From 0c4aea5dfc60b990acaf69a0e744ace36a78310a Mon Sep 17 00:00:00 2001 From: Richard Shadrach Date: Thu, 10 Nov 2022 12:33:44 -0500 Subject: [PATCH 1/5] DEPR: Enforce default of numeric_only=False --- doc/source/whatsnew/v2.0.0.rst | 2 +- pandas/core/frame.py | 69 ++++++--------------- pandas/core/generic.py | 36 +---------- pandas/tests/apply/test_frame_transform.py | 46 +++++--------- pandas/tests/apply/test_series_apply.py | 4 +- pandas/tests/frame/methods/test_cov_corr.py | 33 +++++----- pandas/tests/frame/methods/test_quantile.py | 31 --------- pandas/tests/frame/methods/test_rank.py | 15 ++--- pandas/tests/frame/test_reductions.py | 39 +----------- 9 files changed, 61 insertions(+), 214 deletions(-) diff --git a/doc/source/whatsnew/v2.0.0.rst b/doc/source/whatsnew/v2.0.0.rst index 73a75667b46da..3295e93ab21a0 100644 --- a/doc/source/whatsnew/v2.0.0.rst +++ b/doc/source/whatsnew/v2.0.0.rst @@ -502,7 +502,7 @@ Removal of prior version deprecations/changes - Removed ``na_sentinel`` argument from :func:`factorize`, :meth:`.Index.factorize`, and :meth:`.ExtensionArray.factorize` (:issue:`47157`) - Changed behavior of :meth:`DataFrameGroupBy.apply` and :meth:`SeriesGroupBy.apply` so that ``group_keys`` is respected even if a transformer is detected (:issue:`34998`) - Enforced deprecation ``numeric_only=None`` (the default) in DataFrame reductions that would silently drop columns that raised; ``numeric_only`` now defaults to ``False`` (:issue:`41480`) -- +- Changed default of ``numeric_only`` to ``False`` in all DataFrame methods with that argument (:issue:`46096`, :issue:`46906`) .. --------------------------------------------------------------------------- .. _whatsnew_200.performance: diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 1627a7add25ed..ff795b0a9589c 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -9939,7 +9939,7 @@ def corr( self, method: CorrelationMethod = "pearson", min_periods: int = 1, - numeric_only: bool | lib.NoDefault = lib.no_default, + numeric_only: bool = False, ) -> DataFrame: """ Compute pairwise correlation of columns, excluding NA/null values. @@ -9960,15 +9960,11 @@ def corr( Minimum number of observations required per pair of columns to have a valid result. Currently only available for Pearson and Spearman correlation. - numeric_only : bool, default True + numeric_only : bool, default False Include only `float`, `int` or `boolean` data. .. versionadded:: 1.5.0 - .. deprecated:: 1.5.0 - The default value of ``numeric_only`` will be ``False`` in a future - version of pandas. - Returns ------- DataFrame @@ -10007,11 +10003,7 @@ def corr( dogs 1.0 NaN cats NaN 1.0 """ # noqa:E501 - numeric_only_bool = com.resolve_numeric_only(numeric_only) - data = self._get_numeric_data() if numeric_only_bool else self - if numeric_only is lib.no_default and len(data.columns) < len(self.columns): - com.deprecate_numeric_only_default(type(self), "corr") - + data = self._get_numeric_data() if numeric_only else self cols = data.columns idx = cols.copy() mat = data.to_numpy(dtype=float, na_value=np.nan, copy=False) @@ -10058,7 +10050,7 @@ def cov( self, min_periods: int | None = None, ddof: int | None = 1, - numeric_only: bool | lib.NoDefault = lib.no_default, + numeric_only: bool = False, ) -> DataFrame: """ Compute pairwise covariance of columns, excluding NA/null values. @@ -10090,15 +10082,11 @@ def cov( .. versionadded:: 1.1.0 - numeric_only : bool, default True + numeric_only : bool, default False Include only `float`, `int` or `boolean` data. .. versionadded:: 1.5.0 - .. deprecated:: 1.5.0 - The default value of ``numeric_only`` will be ``False`` in a future - version of pandas. - Returns ------- DataFrame @@ -10168,11 +10156,7 @@ def cov( b NaN 1.248003 0.191417 c -0.150812 0.191417 0.895202 """ - numeric_only_bool = com.resolve_numeric_only(numeric_only) - data = self._get_numeric_data() if numeric_only_bool else self - if numeric_only is lib.no_default and len(data.columns) < len(self.columns): - com.deprecate_numeric_only_default(type(self), "cov") - + data = self._get_numeric_data() if numeric_only else self cols = data.columns idx = cols.copy() mat = data.to_numpy(dtype=float, na_value=np.nan, copy=False) @@ -10196,7 +10180,7 @@ def corrwith( axis: Axis = 0, drop: bool = False, method: CorrelationMethod = "pearson", - numeric_only: bool | lib.NoDefault = lib.no_default, + numeric_only: bool = False, ) -> Series: """ Compute pairwise correlation. @@ -10224,15 +10208,11 @@ def corrwith( * callable: callable with input two 1d ndarrays and returning a float. - numeric_only : bool, default True + numeric_only : bool, default False Include only `float`, `int` or `boolean` data. .. versionadded:: 1.5.0 - .. deprecated:: 1.5.0 - The default value of ``numeric_only`` will be ``False`` in a future - version of pandas. - Returns ------- Series @@ -10264,15 +10244,12 @@ def corrwith( dtype: float64 """ # noqa:E501 axis = self._get_axis_number(axis) - numeric_only_bool = com.resolve_numeric_only(numeric_only) - this = self._get_numeric_data() if numeric_only_bool else self - if numeric_only is lib.no_default and len(this.columns) < len(self.columns): - com.deprecate_numeric_only_default(type(self), "corrwith") + this = self._get_numeric_data() if numeric_only else self if isinstance(other, Series): return this.apply(lambda x: other.corr(x, method=method), axis=axis) - if numeric_only_bool: + if numeric_only: other = other._get_numeric_data() left, right = this.align(other, join="inner", copy=False) @@ -10286,14 +10263,14 @@ def corrwith( right = right + left * 0 # demeaned data - ldem = left - left.mean(numeric_only=numeric_only_bool) - rdem = right - right.mean(numeric_only=numeric_only_bool) + ldem = left - left.mean(numeric_only=numeric_only) + rdem = right - right.mean(numeric_only=numeric_only) num = (ldem * rdem).sum() dom = ( (left.count() - 1) - * left.std(numeric_only=numeric_only_bool) - * right.std(numeric_only=numeric_only_bool) + * left.std(numeric_only=numeric_only) + * right.std(numeric_only=numeric_only) ) correl = num / dom @@ -10801,7 +10778,7 @@ def quantile( self, q: float = ..., axis: Axis = ..., - numeric_only: bool | lib.NoDefault = ..., + numeric_only: bool = ..., interpolation: QuantileInterpolation = ..., ) -> Series: ... @@ -10811,7 +10788,7 @@ def quantile( self, q: AnyArrayLike | Sequence[float], axis: Axis = ..., - numeric_only: bool | lib.NoDefault = ..., + numeric_only: bool = ..., interpolation: QuantileInterpolation = ..., ) -> Series | DataFrame: ... @@ -10821,7 +10798,7 @@ def quantile( self, q: float | AnyArrayLike | Sequence[float] = ..., axis: Axis = ..., - numeric_only: bool | lib.NoDefault = ..., + numeric_only: bool = ..., interpolation: QuantileInterpolation = ..., ) -> Series | DataFrame: ... @@ -10830,7 +10807,7 @@ def quantile( self, q: float | AnyArrayLike | Sequence[float] = 0.5, axis: Axis = 0, - numeric_only: bool | lib.NoDefault = no_default, + numeric_only: bool = False, interpolation: QuantileInterpolation = "linear", method: Literal["single", "table"] = "single", ) -> Series | DataFrame: @@ -10843,13 +10820,8 @@ def quantile( Value between 0 <= q <= 1, the quantile(s) to compute. axis : {0 or 'index', 1 or 'columns'}, default 0 Equals 0 or 'index' for row-wise, 1 or 'columns' for column-wise. - numeric_only : bool, default True - If False, the quantile of datetime and timedelta data will be - computed as well. - - .. deprecated:: 1.5.0 - The default value of ``numeric_only`` will be ``False`` in a future - version of pandas. + numeric_only : bool, default False + Include only `float`, `int` or `boolean` data. interpolation : {'linear', 'lower', 'higher', 'midpoint', 'nearest'} This optional parameter specifies the interpolation method to use, @@ -10924,7 +10896,6 @@ def quantile( any_not_numeric = any(not is_numeric_dtype(x) for x in self.dtypes) if numeric_only is no_default and any_not_numeric: com.deprecate_numeric_only_default(type(self), "quantile") - numeric_only = com.resolve_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 d26a11eae9f7f..c578ff39f080b 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -8853,7 +8853,7 @@ def rank( self: NDFrameT, axis: Axis = 0, method: str = "average", - numeric_only: bool_t | None | lib.NoDefault = lib.no_default, + numeric_only: bool_t = False, na_option: str = "keep", ascending: bool_t = True, pct: bool_t = False, @@ -8878,7 +8878,7 @@ def rank( * first: ranks assigned in order they appear in the array * dense: like 'min', but rank always increases by 1 between groups. - numeric_only : bool, optional + numeric_only : bool, default False For DataFrame objects, rank only numeric columns if set to True. na_option : {'keep', 'top', 'bottom'}, default 'keep' How to rank NaN values: @@ -8953,20 +8953,6 @@ def rank( 3 spider 8.0 4.0 4.0 4.0 1.000 4 snake NaN NaN NaN 5.0 NaN """ - warned = False - if numeric_only is None: - # GH#45036 - warnings.warn( - f"'numeric_only=None' in {type(self).__name__}.rank is deprecated " - "and will raise in a future version. Pass either 'True' or " - "'False'. 'False' will be the default.", - FutureWarning, - stacklevel=find_stack_level(), - ) - warned = True - elif numeric_only is lib.no_default: - numeric_only = None - axis_int = self._get_axis_number(axis) if na_option not in {"keep", "top", "bottom"}: @@ -9002,24 +8988,6 @@ def ranker(data): ranks_obj = self._constructor(ranks, **data._construct_axes_dict()) return ranks_obj.__finalize__(self, method="rank") - # if numeric_only is None, and we can't get anything, we try with - # numeric_only=True - if numeric_only is None: - try: - return ranker(self) - except TypeError: - numeric_only = True - if not warned: - # Only warn here if we didn't already issue a warning above - # GH#45036 - warnings.warn( - f"Dropping of nuisance columns in {type(self).__name__}.rank " - "is deprecated; in a future version this will raise TypeError. " - "Select only valid columns before calling rank.", - FutureWarning, - stacklevel=find_stack_level(), - ) - if numeric_only: if self.ndim == 1 and not is_numeric_dtype(self.dtype): # GH#47500 diff --git a/pandas/tests/apply/test_frame_transform.py b/pandas/tests/apply/test_frame_transform.py index 73a52534dd0d2..8e385de0b48e0 100644 --- a/pandas/tests/apply/test_frame_transform.py +++ b/pandas/tests/apply/test_frame_transform.py @@ -130,10 +130,6 @@ def func(x): frame_kernels_raise = [x for x in frame_transform_kernels if x not in wont_fail] -@pytest.mark.filterwarnings( - "ignore:Calling Series.rank with numeric_only:FutureWarning" -) -@pytest.mark.filterwarnings("ignore:Dropping of nuisance:FutureWarning") @pytest.mark.parametrize("op", [*frame_kernels_raise, lambda x: x + 1]) def test_transform_bad_dtype(op, frame_or_series, request): # GH 35964 @@ -144,17 +140,13 @@ def test_transform_bad_dtype(op, frame_or_series, request): obj = DataFrame({"A": 3 * [object]}) # DataFrame that will fail on most transforms obj = tm.get_obj(obj, frame_or_series) - if op == "rank": - error = ValueError - msg = "Transform function failed" - else: - error = TypeError - msg = "|".join( - [ - "not supported between instances of 'type' and 'type'", - "unsupported operand type", - ] - ) + error = TypeError + msg = "|".join( + [ + "not supported between instances of 'type' and 'type'", + "unsupported operand type", + ] + ) with pytest.raises(error, match=msg): obj.transform(op) @@ -166,12 +158,6 @@ def test_transform_bad_dtype(op, frame_or_series, request): obj.transform({"A": [op]}) -@pytest.mark.filterwarnings( - "ignore:Dropping of nuisance columns in Series.rank:FutureWarning" -) -@pytest.mark.filterwarnings( - "ignore:Calling Series.rank with numeric_only:FutureWarning" -) @pytest.mark.parametrize("op", frame_kernels_raise) def test_transform_failure_typeerror(request, op): # GH 35964 @@ -183,17 +169,13 @@ def test_transform_failure_typeerror(request, op): # Using object makes most transform kernels fail df = DataFrame({"A": 3 * [object], "B": [1, 2, 3]}) - if op == "rank": - error = ValueError - msg = "Transform function failed" - else: - error = TypeError - msg = "|".join( - [ - "not supported between instances of 'type' and 'type'", - "unsupported operand type", - ] - ) + error = TypeError + msg = "|".join( + [ + "not supported between instances of 'type' and 'type'", + "unsupported operand type", + ] + ) with pytest.raises(error, match=msg): df.transform([op]) diff --git a/pandas/tests/apply/test_series_apply.py b/pandas/tests/apply/test_series_apply.py index e0d3510ac3865..5986f1f6cf51d 100644 --- a/pandas/tests/apply/test_series_apply.py +++ b/pandas/tests/apply/test_series_apply.py @@ -275,8 +275,6 @@ def test_transform(string_series): tm.assert_series_equal(result.reindex_like(expected), expected) -@pytest.mark.filterwarnings("ignore:Calling Series.rank:FutureWarning") -@pytest.mark.filterwarnings("ignore:Dropping of nuisance:FutureWarning") @pytest.mark.parametrize("op", series_transform_kernels) def test_transform_partial_failure(op, request): # GH 35964 @@ -288,7 +286,7 @@ def test_transform_partial_failure(op, request): # Using object makes most transform kernels fail ser = Series(3 * [object]) - if op in ("fillna", "ngroup", "rank"): + if op in ("fillna", "ngroup"): error = ValueError msg = "Transform function failed" else: diff --git a/pandas/tests/frame/methods/test_cov_corr.py b/pandas/tests/frame/methods/test_cov_corr.py index 445b90327ed2c..d7333ce03c215 100644 --- a/pandas/tests/frame/methods/test_cov_corr.py +++ b/pandas/tests/frame/methods/test_cov_corr.py @@ -40,11 +40,10 @@ def test_cov(self, float_frame, float_string_frame): expected = frame["A"].cov(frame["C"]) tm.assert_almost_equal(result["A"]["C"], expected) - # exclude non-numeric types - with tm.assert_produces_warning( - FutureWarning, match="The default value of numeric_only" - ): - result = float_string_frame.cov() + # fails on non-numeric types + with pytest.raises(ValueError, match="could not convert string to float"): + float_string_frame.cov() + result = float_string_frame.cov(numeric_only=True) expected = float_string_frame.loc[:, ["A", "B", "C", "D"]].cov() tm.assert_frame_equal(result, expected) @@ -118,11 +117,9 @@ def test_corr_scipy_method(self, float_frame, method): # --------------------------------------------------------------------- def test_corr_non_numeric(self, float_string_frame): - # exclude non-numeric types - with tm.assert_produces_warning( - FutureWarning, match="The default value of numeric_only" - ): - result = float_string_frame.corr() + with pytest.raises(ValueError, match="could not convert string to float"): + float_string_frame.corr() + result = float_string_frame.corr(numeric_only=True) expected = float_string_frame.loc[:, ["A", "B", "C", "D"]].corr() tm.assert_frame_equal(result, expected) @@ -218,7 +215,7 @@ def test_corr_item_cache(self): ser = df["A"] # populate item_cache assert len(df._mgr.arrays) == 2 # i.e. 2 blocks - _ = df.corr() + _ = df.corr(numeric_only=True) # Check that the corr didn't break link between ser and df ser.values[0] = 99 @@ -313,17 +310,15 @@ def test_corrwith_with_objects(self): df1["obj"] = "foo" df2["obj"] = "bar" - with tm.assert_produces_warning( - FutureWarning, match="The default value of numeric_only" - ): - result = df1.corrwith(df2) + with pytest.raises(TypeError, match="Could not convert"): + df1.corrwith(df2) + result = df1.corrwith(df2, numeric_only=True) expected = df1.loc[:, cols].corrwith(df2.loc[:, cols]) tm.assert_series_equal(result, expected) - with tm.assert_produces_warning( - FutureWarning, match="The default value of numeric_only" - ): - result = df1.corrwith(df2, axis=1) + with pytest.raises(TypeError, match="unsupported operand type"): + df1.corrwith(df2, axis=1) + result = df1.corrwith(df2, axis=1, numeric_only=True) expected = df1.loc[:, cols].corrwith(df2.loc[:, cols], axis=1) tm.assert_series_equal(result, expected) diff --git a/pandas/tests/frame/methods/test_quantile.py b/pandas/tests/frame/methods/test_quantile.py index b4661a92c8275..8096af757d3cf 100644 --- a/pandas/tests/frame/methods/test_quantile.py +++ b/pandas/tests/frame/methods/test_quantile.py @@ -25,37 +25,6 @@ def interp_method(request): class TestDataFrameQuantile: - @pytest.mark.parametrize( - "non_num_col", - [ - pd.date_range("2014-01-01", periods=3, freq="m"), - ["a", "b", "c"], - [DataFrame, Series, Timestamp], - ], - ) - def test_numeric_only_default_false_warning( - self, non_num_col, interp_method, request, using_array_manager - ): - # GH #7308 - interpolation, method = interp_method - df = DataFrame({"A": [1, 2, 3], "B": [2, 3, 4]}) - df["C"] = non_num_col - - expected = Series( - [2.0, 3.0], - index=["A", "B"], - name=0.5, - ) - if interpolation == "nearest": - expected = expected.astype(np.int64) - if method == "table" and using_array_manager: - request.node.add_marker( - pytest.mark.xfail(reason="Axis name incorrectly set.") - ) - with tm.assert_produces_warning(FutureWarning, match="numeric_only"): - result = df.quantile(0.5, interpolation=interpolation, method=method) - tm.assert_series_equal(result, expected) - @pytest.mark.parametrize( "df,expected", [ diff --git a/pandas/tests/frame/methods/test_rank.py b/pandas/tests/frame/methods/test_rank.py index 1f5cb95885004..5f648c76d0aa4 100644 --- a/pandas/tests/frame/methods/test_rank.py +++ b/pandas/tests/frame/methods/test_rank.py @@ -136,12 +136,9 @@ def test_rank_mixed_frame(self, float_string_frame): float_string_frame["datetime"] = datetime.now() float_string_frame["timedelta"] = timedelta(days=1, seconds=1) - with tm.assert_produces_warning(FutureWarning, match="numeric_only=None"): - float_string_frame.rank(numeric_only=None) - with tm.assert_produces_warning(FutureWarning, match="Dropping of nuisance"): - result = float_string_frame.rank(1) - expected = float_string_frame.rank(1, numeric_only=True) - tm.assert_frame_equal(result, expected) + float_string_frame.rank(numeric_only=False) + with pytest.raises(TypeError, match="not supported between instances of"): + float_string_frame.rank(axis=1) @td.skip_if_no_scipy def test_rank_na_option(self, float_frame): @@ -491,7 +488,7 @@ def test_rank_object_first(self, frame_or_series, na_option, ascending, expected ) def test_rank_mixed_axis_zero(self, data, expected): df = DataFrame(data) - msg = "Dropping of nuisance columns" - with tm.assert_produces_warning(FutureWarning, match=msg): - result = df.rank() + with pytest.raises(TypeError, match="'<' not supported between instances of"): + df.rank() + result = df.rank(numeric_only=True) tm.assert_frame_equal(result, expected) diff --git a/pandas/tests/frame/test_reductions.py b/pandas/tests/frame/test_reductions.py index 0e5c6057b9a61..d90cdd664258f 100644 --- a/pandas/tests/frame/test_reductions.py +++ b/pandas/tests/frame/test_reductions.py @@ -1,13 +1,11 @@ from datetime import timedelta from decimal import Decimal -import inspect import re from dateutil.tz import tzlocal import numpy as np import pytest -from pandas._libs import lib from pandas.compat import is_platform_windows import pandas.util._test_decorators as td @@ -1697,40 +1695,7 @@ def test_reduction_axis_none_deprecation(method): [ "corr", "corrwith", - "count", "cov", - "mode", - "quantile", - ], -) -def test_numeric_only_deprecation(kernel): - # GH#46852 - df = DataFrame({"a": [1, 2, 3], "b": object}) - args = (df,) if kernel == "corrwith" else () - signature = inspect.signature(getattr(DataFrame, kernel)) - default = signature.parameters["numeric_only"].default - assert default is not True - - if default is None or default is lib.no_default: - expected = getattr(df[["a"]], kernel)(*args) - warn = FutureWarning - else: - # default must be False and works on any nuisance columns - expected = getattr(df, kernel)(*args) - if kernel == "mode": - assert "b" in expected.columns - else: - assert "b" in expected.index - warn = None - msg = f"The default value of numeric_only in DataFrame.{kernel}" - with tm.assert_produces_warning(warn, match=msg): - result = getattr(df, kernel)(*args) - tm.assert_equal(result, expected) - - -@pytest.mark.parametrize( - "kernel", - [ "idxmax", "idxmin", "kurt", @@ -1739,6 +1704,7 @@ def test_numeric_only_deprecation(kernel): "median", "min", "prod", + "quantile", "sem", "skew", "std", @@ -1749,6 +1715,7 @@ def test_numeric_only_deprecation(kernel): def test_fails_on_non_numeric(kernel): # GH#46852 df = DataFrame({"a": [1, 2, 3], "b": object}) + args = (df,) if kernel == "corrwith" else () msg = "|".join( [ "not allowed for this dtype", @@ -1759,4 +1726,4 @@ def test_fails_on_non_numeric(kernel): ] ) with pytest.raises(TypeError, match=msg): - getattr(df, kernel)() + getattr(df, kernel)(*args) From cc1e87619ddd29c21bc3977c26bf12cfdc4a968c Mon Sep 17 00:00:00 2001 From: Richard Shadrach Date: Thu, 10 Nov 2022 12:36:19 -0500 Subject: [PATCH 2/5] Remove unused functions --- pandas/core/common.py | 64 ------------------------------------------- pandas/core/frame.py | 10 ------- 2 files changed, 74 deletions(-) diff --git a/pandas/core/common.py b/pandas/core/common.py index c73c31c2a103b..8764ee0ea6ed7 100644 --- a/pandas/core/common.py +++ b/pandas/core/common.py @@ -25,7 +25,6 @@ cast, overload, ) -import warnings import numpy as np @@ -37,7 +36,6 @@ RandomState, T, ) -from pandas.util._exceptions import find_stack_level from pandas.core.dtypes.cast import construct_1d_object_array_from_listlike from pandas.core.dtypes.common import ( @@ -631,65 +629,3 @@ def fill_missing_names(names: Sequence[Hashable | None]) -> list[Hashable]: list of column names with the None values replaced. """ return [f"level_{i}" if name is None else name for i, name in enumerate(names)] - - -def resolve_numeric_only(numeric_only: bool | None | lib.NoDefault) -> bool: - """Determine the Boolean value of numeric_only. - - See GH#46560 for details on the deprecation. - - Parameters - ---------- - numeric_only : bool, None, or lib.no_default - Value passed to the method. - - Returns - ------- - Resolved value of numeric_only. - """ - if numeric_only is lib.no_default: - # Methods that behave like numeric_only=True and only got the numeric_only - # arg in 1.5.0 default to lib.no_default - result = True - elif numeric_only is None: - # Methods that had the numeric_only arg prior to 1.5.0 and try all columns - # first default to None - result = False - else: - result = numeric_only - return result - - -def deprecate_numeric_only_default( - cls: type, name: str, deprecate_none: bool = False -) -> None: - """Emit FutureWarning message for deprecation of numeric_only. - - See GH#46560 for details on the deprecation. - - Parameters - ---------- - cls : type - pandas type that is generating the warning. - name : str - Name of the method that is generating the warning. - deprecate_none : bool, default False - Whether to also warn about the deprecation of specifying ``numeric_only=None``. - """ - if name in ["all", "any"]: - arg_name = "bool_only" - else: - arg_name = "numeric_only" - - msg = ( - f"The default value of {arg_name} in {cls.__name__}.{name} is " - "deprecated. In a future version, it will default to False. " - ) - if deprecate_none: - msg += f"In addition, specifying '{arg_name}=None' is deprecated. " - msg += ( - f"Select only valid columns or specify the value of {arg_name} to silence " - "this warning." - ) - - warnings.warn(msg, FutureWarning, stacklevel=find_stack_level()) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index ff795b0a9589c..21be0e1d274ed 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -133,7 +133,6 @@ is_integer_dtype, is_iterator, is_list_like, - is_numeric_dtype, is_object_dtype, is_scalar, is_sequence, @@ -10523,12 +10522,6 @@ def _get_data() -> DataFrame: # float64, see test_apply_funcs_over_empty out = out.astype(np.float64) - if numeric_only is None and out.shape[0] != df.shape[1]: - # columns have been dropped GH#41480 - com.deprecate_numeric_only_default( - type(self), name, deprecate_none=True - ) - return out assert not numeric_only and axis == 1 @@ -10893,9 +10886,6 @@ def quantile( """ validate_percentile(q) axis = self._get_axis_number(axis) - any_not_numeric = any(not is_numeric_dtype(x) for x in self.dtypes) - if numeric_only is no_default and any_not_numeric: - com.deprecate_numeric_only_default(type(self), "quantile") if not is_list_like(q): # BlockManager.quantile expects listlike, so we wrap and unwrap here From c5d6f4e19ef886bc5f41d8a3422f8dfe1970a7ce Mon Sep 17 00:00:00 2001 From: Richard Shadrach Date: Thu, 10 Nov 2022 15:22:01 -0500 Subject: [PATCH 3/5] Add versionchanged --- pandas/core/frame.py | 12 ++++++++++++ pandas/core/generic.py | 4 ++++ 2 files changed, 16 insertions(+) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 21be0e1d274ed..ff25cb2f2b6ad 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -9964,6 +9964,9 @@ def corr( .. versionadded:: 1.5.0 + .. versionchanged:: 2.0.0 + The default value of ``numeric_only`` is now ``False``. + Returns ------- DataFrame @@ -10086,6 +10089,9 @@ def cov( .. versionadded:: 1.5.0 + .. versionchanged:: 2.0.0 + The default value of ``numeric_only`` is now ``False``. + Returns ------- DataFrame @@ -10212,6 +10218,9 @@ def corrwith( .. versionadded:: 1.5.0 + .. versionchanged:: 2.0.0 + The default value of ``numeric_only`` is now ``False``. + Returns ------- Series @@ -10816,6 +10825,9 @@ def quantile( numeric_only : bool, default False Include only `float`, `int` or `boolean` data. + .. versionchanged:: 2.0.0 + The default value of ``numeric_only`` is now ``False``. + interpolation : {'linear', 'lower', 'higher', 'midpoint', 'nearest'} This optional parameter specifies the interpolation method to use, when the desired quantile lies between two data points `i` and `j`: diff --git a/pandas/core/generic.py b/pandas/core/generic.py index c578ff39f080b..2cc3cbf04a927 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -8880,6 +8880,10 @@ def rank( numeric_only : bool, default False For DataFrame objects, rank only numeric columns if set to True. + + .. versionchanged:: 2.0.0 + The default value of ``numeric_only`` is now ``False``. + na_option : {'keep', 'top', 'bottom'}, default 'keep' How to rank NaN values: From e13e620382e42bc2bf8c15c26029b3209f9a2711 Mon Sep 17 00:00:00 2001 From: Richard Shadrach Date: Thu, 10 Nov 2022 15:36:07 -0500 Subject: [PATCH 4/5] Add Series.rank to whatsnew --- doc/source/whatsnew/v2.0.0.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v2.0.0.rst b/doc/source/whatsnew/v2.0.0.rst index 1d3facce50eb6..218a7c1cf077c 100644 --- a/doc/source/whatsnew/v2.0.0.rst +++ b/doc/source/whatsnew/v2.0.0.rst @@ -505,7 +505,8 @@ Removal of prior version deprecations/changes - Changed behavior of :meth:`DataFrameGroupBy.apply` and :meth:`SeriesGroupBy.apply` so that ``group_keys`` is respected even if a transformer is detected (:issue:`34998`) - Enforced deprecation ``numeric_only=None`` (the default) in DataFrame reductions that would silently drop columns that raised; ``numeric_only`` now defaults to ``False`` (:issue:`41480`) - Changed default of ``numeric_only`` to ``False`` in all DataFrame methods with that argument (:issue:`46096`, :issue:`46906`) - +- Changed default of ``numeric_only`` to ``False`` in :meth:`Series.rank` (:issue:`47561`) +- .. --------------------------------------------------------------------------- .. _whatsnew_200.performance: From fa151f0334d9794dc7e135c4cb385f5ea48dc13a Mon Sep 17 00:00:00 2001 From: Richard Shadrach Date: Fri, 11 Nov 2022 08:01:23 -0500 Subject: [PATCH 5/5] newline in docs --- doc/source/whatsnew/v2.0.0.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/source/whatsnew/v2.0.0.rst b/doc/source/whatsnew/v2.0.0.rst index 218a7c1cf077c..85d77ccad0b32 100644 --- a/doc/source/whatsnew/v2.0.0.rst +++ b/doc/source/whatsnew/v2.0.0.rst @@ -507,6 +507,7 @@ Removal of prior version deprecations/changes - Changed default of ``numeric_only`` to ``False`` in all DataFrame methods with that argument (:issue:`46096`, :issue:`46906`) - Changed default of ``numeric_only`` to ``False`` in :meth:`Series.rank` (:issue:`47561`) - + .. --------------------------------------------------------------------------- .. _whatsnew_200.performance: