summaryrefslogtreecommitdiff
path: root/numpy/ma
diff options
context:
space:
mode:
Diffstat (limited to 'numpy/ma')
-rw-r--r--numpy/ma/core.py14
-rw-r--r--numpy/ma/tests/test_core.py5
2 files changed, 12 insertions, 7 deletions
diff --git a/numpy/ma/core.py b/numpy/ma/core.py
index 3f136896a..a925eab15 100644
--- a/numpy/ma/core.py
+++ b/numpy/ma/core.py
@@ -3191,16 +3191,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 bba8f2cb7..93f6d4be0 100644
--- a/numpy/ma/tests/test_core.py
+++ b/numpy/ma/tests/test_core.py
@@ -4740,6 +4740,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__":