diff options
author | Eric Wieser <wieser.eric@gmail.com> | 2017-09-28 01:06:23 -0700 |
---|---|---|
committer | Eric Wieser <wieser.eric@gmail.com> | 2017-09-28 01:06:23 -0700 |
commit | 5289102a3bed26744fc694a819f4b25be85b3170 (patch) | |
tree | 60b1eb23fcdbc5f659e87a43fa2345ece1e58643 /numpy/ma/core.py | |
parent | 8671de81cd4558e0360e1ab93dde2360bf3a4320 (diff) | |
download | numpy-5289102a3bed26744fc694a819f4b25be85b3170.tar.gz |
BUG: Shrinking the mask on a structured type errors
Now it is a no-op, as elsewhere in the file. Extract the mask-shrinking into a function.
Diffstat (limited to 'numpy/ma/core.py')
-rw-r--r-- | numpy/ma/core.py | 31 |
1 files changed, 18 insertions, 13 deletions
diff --git a/numpy/ma/core.py b/numpy/ma/core.py index 67a813bf7..be605f0a7 100644 --- a/numpy/ma/core.py +++ b/numpy/ma/core.py @@ -1537,6 +1537,16 @@ def is_mask(m): return False +def _shrink_mask(m): + """ + Shrink a mask to nomask if possible + """ + if not m.dtype.names and not m.any(): + return nomask + else: + return m + + def make_mask(m, copy=False, shrink=True, dtype=MaskType): """ Create a boolean mask from an array. @@ -1621,10 +1631,9 @@ def make_mask(m, copy=False, shrink=True, dtype=MaskType): # Fill the mask in case there are missing data; turn it into an ndarray. result = np.array(filled(m, True), copy=copy, dtype=dtype, subok=True) # Bas les masques ! - if shrink and (not result.dtype.names) and (not result.any()): - return nomask - else: - return result + if shrink: + result = _shrink_mask(result) + return result def make_mask_none(newshape, dtype=None): @@ -3544,9 +3553,7 @@ class MaskedArray(ndarray): False """ - m = self._mask - if m.ndim and not m.any(): - self._mask = nomask + self._mask = _shrink_mask(self._mask) return self baseclass = property(fget=lambda self: self._baseclass, @@ -6659,12 +6666,11 @@ def concatenate(arrays, axis=0): return data # OK, so we have to concatenate the masks dm = np.concatenate([getmaskarray(a) for a in arrays], axis) + dm = dm.reshape(d.shape) + # If we decide to keep a '_shrinkmask' option, we want to check that # all of them are True, and then check for dm.any() - if not dm.dtype.fields and not dm.any(): - data._mask = nomask - else: - data._mask = dm.reshape(d.shape) + data._mask = _shrink_mask(dm) return data @@ -7082,8 +7088,7 @@ def where(condition, x=_NoValue, y=_NoValue): mask = np.where(cm, np.ones((), dtype=mask.dtype), mask) # collapse the mask, for backwards compatibility - if mask.dtype == np.bool_ and not mask.any(): - mask = nomask + mask = _shrink_mask(mask) return masked_array(data, mask=mask) |