Skip to content

DEPR: deprecate unused errors in NDFrame.where/mask #47728

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jul 15, 2022
Merged
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
1 change: 1 addition & 0 deletions doc/source/whatsnew/v1.5.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -11788,6 +11788,7 @@ def where(
...

# error: Signature of "where" incompatible with supertype "NDFrame"
@deprecate_kwarg(old_arg_name="errors", new_arg_name=None)
@deprecate_nonkeyword_arguments(
version=None, allowed_args=["self", "cond", "other"]
)
Expand All @@ -11807,7 +11808,6 @@ def where( # type: ignore[override]
inplace=inplace,
axis=axis,
level=level,
errors=errors,
try_cast=try_cast,
)

Expand Down Expand Up @@ -11854,6 +11854,7 @@ def mask(
...

# error: Signature of "mask" incompatible with supertype "NDFrame"
@deprecate_kwarg(old_arg_name="errors", new_arg_name=None)
@deprecate_nonkeyword_arguments(
version=None, allowed_args=["self", "cond", "other"]
)
Expand All @@ -11873,7 +11874,6 @@ def mask( # type: ignore[override]
inplace=inplace,
axis=axis,
level=level,
errors=errors,
try_cast=try_cast,
)

Expand Down
9 changes: 6 additions & 3 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -9548,6 +9547,7 @@ def where(
) -> NDFrameT | None:
...

@deprecate_kwarg(old_arg_name="errors", new_arg_name=None)
@deprecate_nonkeyword_arguments(
version=None, allowed_args=["self", "cond", "other"]
)
Expand Down Expand Up @@ -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).
Expand Down Expand Up @@ -9721,7 +9724,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(
Expand Down Expand Up @@ -9765,6 +9768,7 @@ def mask(
) -> NDFrameT | None:
...

@deprecate_kwarg(old_arg_name="errors", new_arg_name=None)
@deprecate_nonkeyword_arguments(
version=None, allowed_args=["self", "cond", "other"]
)
Expand Down Expand Up @@ -9808,7 +9812,6 @@ def mask(
inplace=inplace,
axis=axis,
level=level,
errors=errors,
)

@doc(klass=_shared_doc_kwargs["klass"])
Expand Down
5 changes: 3 additions & 2 deletions pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
from pandas.util._decorators import (
Appender,
Substitution,
deprecate_kwarg,
deprecate_nonkeyword_arguments,
doc,
)
Expand Down Expand Up @@ -6069,6 +6070,7 @@ def where(
...

# error: Signature of "where" incompatible with supertype "NDFrame"
@deprecate_kwarg(old_arg_name="errors", new_arg_name=None)
@deprecate_nonkeyword_arguments(
version=None, allowed_args=["self", "cond", "other"]
)
Expand All @@ -6088,7 +6090,6 @@ def where( # type: ignore[override]
inplace=inplace,
axis=axis,
level=level,
errors=errors,
try_cast=try_cast,
)

Expand Down Expand Up @@ -6135,6 +6136,7 @@ def mask(
...

# error: Signature of "mask" incompatible with supertype "NDFrame"
@deprecate_kwarg(old_arg_name="errors", new_arg_name=None)
@deprecate_nonkeyword_arguments(
version=None, allowed_args=["self", "cond", "other"]
)
Expand All @@ -6154,7 +6156,6 @@ def mask( # type: ignore[override]
inplace=inplace,
axis=axis,
level=level,
errors=errors,
try_cast=try_cast,
)

Expand Down
14 changes: 14 additions & 0 deletions pandas/tests/frame/indexing/test_where.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")