From 1266df05d7b18a60cc68dc44923d22e7c2c77123 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torsten=20W=C3=B6rtwein?= Date: Thu, 14 Jul 2022 22:11:32 -0400 Subject: [PATCH 1/5] DEPR: deprecate unused errors in NDFrame.where/mask --- pandas/core/frame.py | 2 -- pandas/core/generic.py | 6 +++--- pandas/core/series.py | 2 -- 3 files changed, 3 insertions(+), 7 deletions(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index ead4ea744c647..f3fa4ff3342f4 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -11807,7 +11807,6 @@ def where( # type: ignore[override] inplace=inplace, axis=axis, level=level, - errors=errors, try_cast=try_cast, ) @@ -11873,7 +11872,6 @@ def mask( # type: ignore[override] inplace=inplace, axis=axis, level=level, - errors=errors, try_cast=try_cast, ) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 4325f0eb04a9c..25663e142419c 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -9381,7 +9381,6 @@ def _where( inplace=False, axis=None, level=None, - errors: IgnoreRaise | lib.NoDefault = "raise", ): """ Equivalent to public method `where`, except that `other` is not @@ -9548,6 +9547,7 @@ def where( ) -> NDFrameT | None: ... + @deprecate_kwarg(old_arg_name="errors") @deprecate_nonkeyword_arguments( version=None, allowed_args=["self", "cond", "other"] ) @@ -9721,7 +9721,7 @@ def where( stacklevel=find_stack_level(), ) - return self._where(cond, other, inplace, axis, level, errors=errors) + return self._where(cond, other, inplace, axis, level) @overload def mask( @@ -9765,6 +9765,7 @@ def mask( ) -> NDFrameT | None: ... + @deprecate_kwarg(old_arg_name="errors") @deprecate_nonkeyword_arguments( version=None, allowed_args=["self", "cond", "other"] ) @@ -9808,7 +9809,6 @@ def mask( inplace=inplace, axis=axis, level=level, - errors=errors, ) @doc(klass=_shared_doc_kwargs["klass"]) diff --git a/pandas/core/series.py b/pandas/core/series.py index ef4ea0172c505..04191e1bf1e67 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -6088,7 +6088,6 @@ def where( # type: ignore[override] inplace=inplace, axis=axis, level=level, - errors=errors, try_cast=try_cast, ) @@ -6154,7 +6153,6 @@ def mask( # type: ignore[override] inplace=inplace, axis=axis, level=level, - errors=errors, try_cast=try_cast, ) From 137e897c2192fe385eee3d7d7a15438a3848d143 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torsten=20W=C3=B6rtwein?= Date: Thu, 14 Jul 2022 23:00:14 -0400 Subject: [PATCH 2/5] add warnings in series/dataframe --- pandas/core/frame.py | 2 ++ pandas/core/series.py | 2 ++ 2 files changed, 4 insertions(+) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index f3fa4ff3342f4..56df3cb1b4189 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -11788,6 +11788,7 @@ def where( ... # error: Signature of "where" incompatible with supertype "NDFrame" + @deprecate_kwarg(old_arg_name="errors") @deprecate_nonkeyword_arguments( version=None, allowed_args=["self", "cond", "other"] ) @@ -11853,6 +11854,7 @@ def mask( ... # error: Signature of "mask" incompatible with supertype "NDFrame" + @deprecate_kwarg(old_arg_name="errors") @deprecate_nonkeyword_arguments( version=None, allowed_args=["self", "cond", "other"] ) diff --git a/pandas/core/series.py b/pandas/core/series.py index 04191e1bf1e67..74021f325f66d 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -6069,6 +6069,7 @@ def where( ... # error: Signature of "where" incompatible with supertype "NDFrame" + @deprecate_kwarg(old_arg_name="errors") @deprecate_nonkeyword_arguments( version=None, allowed_args=["self", "cond", "other"] ) @@ -6134,6 +6135,7 @@ def mask( ... # error: Signature of "mask" incompatible with supertype "NDFrame" + @deprecate_kwarg(old_arg_name="errors") @deprecate_nonkeyword_arguments( version=None, allowed_args=["self", "cond", "other"] ) From d7dd2debfee2c91d9db0edb528c018ddad0a636e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torsten=20W=C3=B6rtwein?= Date: Thu, 14 Jul 2022 23:19:43 -0400 Subject: [PATCH 3/5] new_arg_name=None --- pandas/core/frame.py | 4 ++-- pandas/core/generic.py | 4 ++-- pandas/core/series.py | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 56df3cb1b4189..e70312c562907 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -11788,7 +11788,7 @@ def where( ... # error: Signature of "where" incompatible with supertype "NDFrame" - @deprecate_kwarg(old_arg_name="errors") + @deprecate_kwarg(old_arg_name="errors", new_arg_name=None) @deprecate_nonkeyword_arguments( version=None, allowed_args=["self", "cond", "other"] ) @@ -11854,7 +11854,7 @@ def mask( ... # error: Signature of "mask" incompatible with supertype "NDFrame" - @deprecate_kwarg(old_arg_name="errors") + @deprecate_kwarg(old_arg_name="errors", new_arg_name=None) @deprecate_nonkeyword_arguments( version=None, allowed_args=["self", "cond", "other"] ) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 25663e142419c..420fe8f8654ed 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -9547,7 +9547,7 @@ def where( ) -> NDFrameT | None: ... - @deprecate_kwarg(old_arg_name="errors") + @deprecate_kwarg(old_arg_name="errors", new_arg_name=None) @deprecate_nonkeyword_arguments( version=None, allowed_args=["self", "cond", "other"] ) @@ -9765,7 +9765,7 @@ def mask( ) -> NDFrameT | None: ... - @deprecate_kwarg(old_arg_name="errors") + @deprecate_kwarg(old_arg_name="errors", new_arg_name=None) @deprecate_nonkeyword_arguments( version=None, allowed_args=["self", "cond", "other"] ) diff --git a/pandas/core/series.py b/pandas/core/series.py index 74021f325f66d..f86ca8424e117 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -6069,7 +6069,7 @@ def where( ... # error: Signature of "where" incompatible with supertype "NDFrame" - @deprecate_kwarg(old_arg_name="errors") + @deprecate_kwarg(old_arg_name="errors", new_arg_name=None) @deprecate_nonkeyword_arguments( version=None, allowed_args=["self", "cond", "other"] ) @@ -6135,7 +6135,7 @@ def mask( ... # error: Signature of "mask" incompatible with supertype "NDFrame" - @deprecate_kwarg(old_arg_name="errors") + @deprecate_kwarg(old_arg_name="errors", new_arg_name=None) @deprecate_nonkeyword_arguments( version=None, allowed_args=["self", "cond", "other"] ) From 075896b2e953be35efb64b0d88d7649670a63f64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torsten=20W=C3=B6rtwein?= Date: Fri, 15 Jul 2022 08:10:40 -0400 Subject: [PATCH 4/5] missing import --- pandas/core/series.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pandas/core/series.py b/pandas/core/series.py index f86ca8424e117..60898ee75f7c2 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -61,6 +61,7 @@ from pandas.util._decorators import ( Appender, Substitution, + deprecate_kwarg, deprecate_nonkeyword_arguments, doc, ) From ecce4d1a6cfd3ccd3c1c02479aee60bc62eaacae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torsten=20W=C3=B6rtwein?= Date: Fri, 15 Jul 2022 09:58:33 -0400 Subject: [PATCH 5/5] test, doc-string, and whatsnew --- doc/source/whatsnew/v1.5.0.rst | 1 + pandas/core/generic.py | 3 +++ pandas/tests/frame/indexing/test_where.py | 14 ++++++++++++++ 3 files changed, 18 insertions(+) diff --git a/doc/source/whatsnew/v1.5.0.rst b/doc/source/whatsnew/v1.5.0.rst index 9651269963803..112f5f08a3393 100644 --- a/doc/source/whatsnew/v1.5.0.rst +++ b/doc/source/whatsnew/v1.5.0.rst @@ -771,6 +771,7 @@ Other Deprecations - Clarified warning from :func:`to_datetime` when delimited dates can't be parsed in accordance to specified ``dayfirst`` argument (:issue:`46210`) - Deprecated :class:`Series` and :class:`Resampler` reducers (e.g. ``min``, ``max``, ``sum``, ``mean``) raising a ``NotImplementedError`` when the dtype is non-numric and ``numeric_only=True`` is provided; this will raise a ``TypeError`` in a future version (:issue:`47500`) - Deprecated :meth:`Series.rank` returning an empty result when the dtype is non-numeric and ``numeric_only=True`` is provided; this will raise a ``TypeError`` in a future version (:issue:`47500`) +- Deprecated argument ``errors`` for :meth:`Series.mask`, :meth:`Series.where`, :meth:`DataFrame.mask`, and :meth:`DataFrame.where` as ``errors`` had no effect on this methods (:issue:`47728`) .. --------------------------------------------------------------------------- .. _whatsnew_150.performance: diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 420fe8f8654ed..6e00f33f486d9 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -9599,6 +9599,9 @@ def where( - 'raise' : allow exceptions to be raised. - 'ignore' : suppress exceptions. On error return original object. + .. deprecated:: 1.5.0 + This argument had no effect. + try_cast : bool, default None Try to cast the result back to the input type (if possible). diff --git a/pandas/tests/frame/indexing/test_where.py b/pandas/tests/frame/indexing/test_where.py index 9d004613116b8..5b9883f3866e7 100644 --- a/pandas/tests/frame/indexing/test_where.py +++ b/pandas/tests/frame/indexing/test_where.py @@ -1035,3 +1035,17 @@ def test_where_dt64_2d(): mask[:] = True expected = df _check_where_equivalences(df, mask, other, expected) + + +def test_where_mask_deprecated(frame_or_series): + # GH 47728 + obj = DataFrame(np.random.randn(4, 3)) + obj = tm.get_obj(obj, frame_or_series) + + mask = obj > 0 + + with tm.assert_produces_warning(FutureWarning): + obj.where(mask, -1, errors="raise") + + with tm.assert_produces_warning(FutureWarning): + obj.mask(mask, -1, errors="raise")