Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcoGorelli committed May 26, 2021
1 parent 7861647 commit 01881bb
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 12 deletions.
15 changes: 15 additions & 0 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -10697,6 +10697,21 @@ def where(
):
return super().where(cond, other, inplace, axis, level, errors, try_cast)

@deprecate_nonkeyword_arguments(
version=None, allowed_args=["self", "cond", "other"]
)
def mask(
self,
cond,
other=np.nan,
inplace=False,
axis=None,
level=None,
errors="raise",
try_cast=lib.no_default,
):
return super().mask(cond, other, inplace, axis, level, errors, try_cast)


DataFrame._add_numeric_operations()

Expand Down
6 changes: 1 addition & 5 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@
InvalidIndexError,
)
from pandas.util._decorators import (
deprecate_nonkeyword_arguments,
doc,
rewrite_axis_style_signature,
)
Expand Down Expand Up @@ -9126,9 +9125,6 @@ def where(
name="mask",
name_other="where",
)
@deprecate_nonkeyword_arguments(
version=None, allowed_args=["self", "cond", "other"]
)
def mask(
self,
cond,
Expand All @@ -9148,7 +9144,7 @@ def mask(
"try_cast keyword is deprecated and will be removed in a "
"future version",
FutureWarning,
stacklevel=3,
stacklevel=4,
)

# see gh-21891
Expand Down
15 changes: 15 additions & 0 deletions pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -5343,6 +5343,21 @@ def where(
):
return super().where(cond, other, inplace, axis, level, errors, try_cast)

@deprecate_nonkeyword_arguments(
version=None, allowed_args=["self", "cond", "other"]
)
def mask(
self,
cond,
other=np.nan,
inplace=False,
axis=None,
level=None,
errors="raise",
try_cast=lib.no_default,
):
return super().mask(cond, other, inplace, axis, level, errors, try_cast)

# ----------------------------------------------------------------------
# Add index
_AXIS_ORDERS = ["index"]
Expand Down
6 changes: 1 addition & 5 deletions pandas/tests/frame/indexing/test_mask.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,18 +93,14 @@ def test_mask_dtype_bool_conversion(self):
def test_mask_pos_args_deprecation(self):
# https://github.com/pandas-dev/pandas/issues/41485
df = DataFrame({"a": range(5)})

expected = DataFrame({"a": [-1, 1, -1, 3, -1]})
cond = df % 2 == 0

msg = (
r"In a future version of pandas all arguments of NDFrame.mask except for "
r"In a future version of pandas all arguments of DataFrame.mask except for "
r"the arguments 'cond' and 'other' will be keyword-only"
)

with tm.assert_produces_warning(FutureWarning, match=msg):
result = df.mask(cond, -1, False)

tm.assert_frame_equal(result, expected)


Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/series/indexing/test_mask.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def test_mask_pos_args_deprecation():
cond = s % 2 == 0

msg = (
r"In a future version of pandas all arguments of NDFrame.mask except for "
r"In a future version of pandas all arguments of Series.mask except for "
r"the arguments 'cond' and 'other' will be keyword-only"
)

Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/series/indexing/test_where.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ def test_broadcast(size, mask, item, box):
tm.assert_series_equal(result, expected)

s = Series(data)
result = s.mask(selection, other=box(item))
result = s.mask(selection, box(item))
tm.assert_series_equal(result, expected)


Expand Down

0 comments on commit 01881bb

Please sign in to comment.