Skip to content

Commit 7be9400

Browse files
fixed Series.mask code
1 parent 6c47024 commit 7be9400

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

pandas/core/generic.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -10472,7 +10472,8 @@ def mask(
1047210472
cond = common.apply_if_callable(cond, self)
1047310473

1047410474
# see gh-21891
10475-
if not hasattr(cond, "__invert__"):
10475+
if not hasattr(cond, "shape"):
10476+
# not testing __invert__, since `~True` is `-2`.
1047610477
cond = np.array(cond)
1047710478

1047810479
return self.where(

pandas/tests/series/indexing/test_mask.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,11 @@ def test_mask():
3131
rs2 = s2.mask(cond[:3], -s2)
3232
tm.assert_series_equal(rs, rs2)
3333

34+
# test scalar
35+
assert s.mask(True).isna().all()
36+
tm.assert_series_equal(s.mask(False), s)
37+
3438
msg = "Array conditional must be same shape as self"
35-
with pytest.raises(ValueError, match=msg):
36-
s.mask(1)
3739
with pytest.raises(ValueError, match=msg):
3840
s.mask(cond[:3].values, -s)
3941

0 commit comments

Comments
 (0)