Skip to content

Commit

Permalink
BUG: ma.masked_values does not shrink mask if requested
Browse files Browse the repository at this point in the history
When called with the shrink parameter set to False, np.ma.masked_values
will create a False filled array mask and not shrink the mask.
Previously the mask would be shrunk to a single False scalar.

closes #2674
  • Loading branch information
jjhelmus committed Oct 21, 2015
1 parent 4750c28 commit 8da9c71
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 2 additions & 2 deletions numpy/ma/core.py
Expand Up @@ -1544,7 +1544,7 @@ def make_mask(m, copy=False, shrink=True, dtype=MaskType):
dtype=[('man', '|b1'), ('mouse', '|b1')])
"""
if m is nomask:
if m is nomask and shrink:
return nomask
elif isinstance(m, ndarray):
# We won't return after this point to make sure we can shrink the mask
Expand Down Expand Up @@ -2247,7 +2247,7 @@ def masked_values(x, value, rtol=1e-5, atol=1e-8, copy=True, shrink=True):
else:
condition = umath.equal(xnew, value)
mask = nomask
mask = mask_or(mask, make_mask(condition, shrink=shrink))
mask = mask_or(mask, make_mask(condition, shrink=shrink), shrink=shrink)
return masked_array(xnew, mask=mask, copy=copy, fill_value=value)


Expand Down
5 changes: 5 additions & 0 deletions numpy/ma/tests/test_core.py
Expand Up @@ -1145,6 +1145,11 @@ def test_noshrinking(self):
a /= 1.
assert_equal(a.mask, [0, 0, 0])

def test_noshink_on_creation(self):
# Check that the mask is not shrunk on array creation when not wanted
a = np.ma.masked_values([1., 2.5, 3.1], 1.5, shrink=False)
assert_equal(a.mask, [0, 0, 0])

def test_mod(self):
# Tests mod
(x, y, a10, m1, m2, xm, ym, z, zm, xf) = self.d
Expand Down

0 comments on commit 8da9c71

Please sign in to comment.