Skip to content

Commit

Permalink
fix mask to not raise warning twice
Browse files Browse the repository at this point in the history
  • Loading branch information
jorisvandenbossche committed Nov 27, 2023
1 parent ed255e1 commit dc3100d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 10 deletions.
3 changes: 2 additions & 1 deletion pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -10907,12 +10907,13 @@ def mask(
)

cond = common.apply_if_callable(cond, self)
other = common.apply_if_callable(other, self)

# see gh-21891
if not hasattr(cond, "__invert__"):
cond = np.array(cond)

return self.where(
return self._where(
~cond,
other=other,
inplace=inplace,
Expand Down
12 changes: 3 additions & 9 deletions pandas/tests/copy_view/test_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -1552,20 +1552,14 @@ def test_chained_where_mask(using_copy_on_write, func):
getattr(df[["a"]], func)(df["a"] > 2, 5, inplace=True)
tm.assert_frame_equal(df, df_orig)
else:
with tm.assert_produces_warning(
FutureWarning, match="inplace method", check_stacklevel=False
):
with tm.assert_produces_warning(FutureWarning, match="inplace method"):
getattr(df["a"], func)(df["a"] > 2, 5, inplace=True)

with tm.assert_produces_warning(
FutureWarning, match="inplace method", check_stacklevel=False
):
with tm.assert_produces_warning(FutureWarning, match="inplace method"):
with option_context("mode.chained_assignment", None):
getattr(df[["a"]], func)(df["a"] > 2, 5, inplace=True)

with tm.assert_produces_warning(
FutureWarning, match="inplace method", check_stacklevel=False
):
with tm.assert_produces_warning(FutureWarning, match="inplace method"):
with option_context("mode.chained_assignment", None):
getattr(df[df["a"] > 1], func)(df["a"] > 2, 5, inplace=True)

Expand Down

0 comments on commit dc3100d

Please sign in to comment.