Skip to content

Commit

Permalink
BUG: Undo behavior change in ma.masked_values(shrink=True)
Browse files Browse the repository at this point in the history
This change was introduced as part of numpy#10232

Fixes numpy#11112
  • Loading branch information
eric-wieser committed Jun 10, 2018
1 parent 3bb11d6 commit 51dc6f4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
6 changes: 4 additions & 2 deletions numpy/ma/core.py
Expand Up @@ -2319,8 +2319,10 @@ def masked_values(x, value, rtol=1e-5, atol=1e-8, copy=True, shrink=True):
mask = np.isclose(xnew, value, atol=atol, rtol=rtol)
else:
mask = umath.equal(xnew, value)
return masked_array(
xnew, mask=mask, copy=copy, fill_value=value, shrink=shrink)
ret = masked_array(xnew, mask=mask, copy=copy, fill_value=value)
if shrink:
ret.shrink_mask()
return ret


def masked_invalid(a, copy=True):
Expand Down
6 changes: 6 additions & 0 deletions numpy/ma/tests/test_core.py
Expand Up @@ -4904,6 +4904,12 @@ def test_masked_values(self):
res = np.ma.masked_values(np.inf, -np.inf)
assert_equal(res.mask, False)

res = np.ma.masked_values([1, 2, 3, 4], 5, shrink=True)
assert_(res.mask is np.ma.nomask)

res = np.ma.masked_values([1, 2, 3, 4], 5, shrink=False)
assert_equal(res.mask, [False] * 4)


def test_masked_array():
a = np.ma.array([0, 1, 2, 3], mask=[0, 0, 1, 0])
Expand Down

0 comments on commit 51dc6f4

Please sign in to comment.