summaryrefslogtreecommitdiff
path: root/numpy/ma
diff options
context:
space:
mode:
authorEric Wieser <wieser.eric@gmail.com>2017-06-27 20:25:36 +0100
committerEric Wieser <wieser.eric@gmail.com>2017-06-27 20:39:32 +0100
commit7175f1c4a9858994607cfb207a0e28468ef544f6 (patch)
tree8d48c11f157f415be834d77c41d9a1202bb0caae /numpy/ma
parentf5eb5af5d47d4c59159a424169619d45d2140b67 (diff)
downloadnumpy-7175f1c4a9858994607cfb207a0e28468ef544f6.tar.gz
BUG: MaskedArray.astype fails for non-trivial structured types
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__":