diff options
Diffstat (limited to 'numpy/ma')
-rw-r--r-- | numpy/ma/core.py | 14 | ||||
-rw-r--r-- | numpy/ma/tests/test_core.py | 5 |
2 files changed, 12 insertions, 7 deletions
diff --git a/numpy/ma/core.py b/numpy/ma/core.py index c2b10d5f8..ab4364706 100644 --- a/numpy/ma/core.py +++ b/numpy/ma/core.py @@ -3152,16 +3152,16 @@ class MaskedArray(ndarray): """ newtype = np.dtype(newtype) + newmasktype = make_mask_descr(newtype) + output = self._data.astype(newtype).view(type(self)) output._update_from(self) - names = output.dtype.names - if names is None: - output._mask = self._mask.astype(bool) + + if self._mask is nomask: + output._mask = nomask else: - if self._mask is nomask: - output._mask = nomask - else: - output._mask = self._mask.astype([(n, bool) for n in names]) + output._mask = self._mask.astype(newmasktype) + # Don't check _fill_value if it's None, that'll speed things up if self._fill_value is not None: output._fill_value = _check_fill_value(self._fill_value, newtype) diff --git a/numpy/ma/tests/test_core.py b/numpy/ma/tests/test_core.py index 816e149a9..707fcd1de 100644 --- a/numpy/ma/tests/test_core.py +++ b/numpy/ma/tests/test_core.py @@ -4788,6 +4788,11 @@ def test_ufunc_with_output(): y = np.add(x, 1., out=x) assert_(y is x) +def test_astype(): + descr = [('v', int, 3), ('x', [('y', float)])] + x = array(([1, 2, 3], (1.0,)), dtype=descr) + assert_equal(x, x.astype(descr)) + ############################################################################### if __name__ == "__main__": |