Skip to content

Commit ff74bb6

Browse files
authored
DEPR: deprecate unused errors in NDFrame.where/mask (#47728)
* DEPR: deprecate unused errors in NDFrame.where/mask * add warnings in series/dataframe * new_arg_name=None * missing import * test, doc-string, and whatsnew
1 parent 0a8b45f commit ff74bb6

File tree

5 files changed

+26
-7
lines changed

5 files changed

+26
-7
lines changed

doc/source/whatsnew/v1.5.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -771,6 +771,7 @@ Other Deprecations
771771
- Clarified warning from :func:`to_datetime` when delimited dates can't be parsed in accordance to specified ``dayfirst`` argument (:issue:`46210`)
772772
- 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`)
773773
- 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`)
774+
- 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`)
774775

775776
.. ---------------------------------------------------------------------------
776777
.. _whatsnew_150.performance:

pandas/core/frame.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -11788,6 +11788,7 @@ def where(
1178811788
...
1178911789

1179011790
# error: Signature of "where" incompatible with supertype "NDFrame"
11791+
@deprecate_kwarg(old_arg_name="errors", new_arg_name=None)
1179111792
@deprecate_nonkeyword_arguments(
1179211793
version=None, allowed_args=["self", "cond", "other"]
1179311794
)
@@ -11807,7 +11808,6 @@ def where( # type: ignore[override]
1180711808
inplace=inplace,
1180811809
axis=axis,
1180911810
level=level,
11810-
errors=errors,
1181111811
try_cast=try_cast,
1181211812
)
1181311813

@@ -11854,6 +11854,7 @@ def mask(
1185411854
...
1185511855

1185611856
# error: Signature of "mask" incompatible with supertype "NDFrame"
11857+
@deprecate_kwarg(old_arg_name="errors", new_arg_name=None)
1185711858
@deprecate_nonkeyword_arguments(
1185811859
version=None, allowed_args=["self", "cond", "other"]
1185911860
)
@@ -11873,7 +11874,6 @@ def mask( # type: ignore[override]
1187311874
inplace=inplace,
1187411875
axis=axis,
1187511876
level=level,
11876-
errors=errors,
1187711877
try_cast=try_cast,
1187811878
)
1187911879

pandas/core/generic.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -9381,7 +9381,6 @@ def _where(
93819381
inplace=False,
93829382
axis=None,
93839383
level=None,
9384-
errors: IgnoreRaise | lib.NoDefault = "raise",
93859384
):
93869385
"""
93879386
Equivalent to public method `where`, except that `other` is not
@@ -9548,6 +9547,7 @@ def where(
95489547
) -> NDFrameT | None:
95499548
...
95509549

9550+
@deprecate_kwarg(old_arg_name="errors", new_arg_name=None)
95519551
@deprecate_nonkeyword_arguments(
95529552
version=None, allowed_args=["self", "cond", "other"]
95539553
)
@@ -9599,6 +9599,9 @@ def where(
95999599
- 'raise' : allow exceptions to be raised.
96009600
- 'ignore' : suppress exceptions. On error return original object.
96019601
9602+
.. deprecated:: 1.5.0
9603+
This argument had no effect.
9604+
96029605
try_cast : bool, default None
96039606
Try to cast the result back to the input type (if possible).
96049607
@@ -9721,7 +9724,7 @@ def where(
97219724
stacklevel=find_stack_level(),
97229725
)
97239726

9724-
return self._where(cond, other, inplace, axis, level, errors=errors)
9727+
return self._where(cond, other, inplace, axis, level)
97259728

97269729
@overload
97279730
def mask(
@@ -9765,6 +9768,7 @@ def mask(
97659768
) -> NDFrameT | None:
97669769
...
97679770

9771+
@deprecate_kwarg(old_arg_name="errors", new_arg_name=None)
97689772
@deprecate_nonkeyword_arguments(
97699773
version=None, allowed_args=["self", "cond", "other"]
97709774
)
@@ -9808,7 +9812,6 @@ def mask(
98089812
inplace=inplace,
98099813
axis=axis,
98109814
level=level,
9811-
errors=errors,
98129815
)
98139816

98149817
@doc(klass=_shared_doc_kwargs["klass"])

pandas/core/series.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
from pandas.util._decorators import (
6262
Appender,
6363
Substitution,
64+
deprecate_kwarg,
6465
deprecate_nonkeyword_arguments,
6566
doc,
6667
)
@@ -6069,6 +6070,7 @@ def where(
60696070
...
60706071

60716072
# error: Signature of "where" incompatible with supertype "NDFrame"
6073+
@deprecate_kwarg(old_arg_name="errors", new_arg_name=None)
60726074
@deprecate_nonkeyword_arguments(
60736075
version=None, allowed_args=["self", "cond", "other"]
60746076
)
@@ -6088,7 +6090,6 @@ def where( # type: ignore[override]
60886090
inplace=inplace,
60896091
axis=axis,
60906092
level=level,
6091-
errors=errors,
60926093
try_cast=try_cast,
60936094
)
60946095

@@ -6135,6 +6136,7 @@ def mask(
61356136
...
61366137

61376138
# error: Signature of "mask" incompatible with supertype "NDFrame"
6139+
@deprecate_kwarg(old_arg_name="errors", new_arg_name=None)
61386140
@deprecate_nonkeyword_arguments(
61396141
version=None, allowed_args=["self", "cond", "other"]
61406142
)
@@ -6154,7 +6156,6 @@ def mask( # type: ignore[override]
61546156
inplace=inplace,
61556157
axis=axis,
61566158
level=level,
6157-
errors=errors,
61586159
try_cast=try_cast,
61596160
)
61606161

pandas/tests/frame/indexing/test_where.py

+14
Original file line numberDiff line numberDiff line change
@@ -1035,3 +1035,17 @@ def test_where_dt64_2d():
10351035
mask[:] = True
10361036
expected = df
10371037
_check_where_equivalences(df, mask, other, expected)
1038+
1039+
1040+
def test_where_mask_deprecated(frame_or_series):
1041+
# GH 47728
1042+
obj = DataFrame(np.random.randn(4, 3))
1043+
obj = tm.get_obj(obj, frame_or_series)
1044+
1045+
mask = obj > 0
1046+
1047+
with tm.assert_produces_warning(FutureWarning):
1048+
obj.where(mask, -1, errors="raise")
1049+
1050+
with tm.assert_produces_warning(FutureWarning):
1051+
obj.mask(mask, -1, errors="raise")

0 commit comments

Comments
 (0)