summaryrefslogtreecommitdiff
path: root/numpy/ma
diff options
context:
space:
mode:
authorahaldane <ealloc@gmail.com>2017-06-27 20:49:06 -0400
committerGitHub <noreply@github.com>2017-06-27 20:49:06 -0400
commit0767d38c8502aab52424ff9907ac1b63dc138597 (patch)
tree190474297a2b1cbb7b780fa032a21a208d5c1ccd /numpy/ma
parent96f146b55cac20ae96cac344cb224c87af87d0a9 (diff)
parent7175f1c4a9858994607cfb207a0e28468ef544f6 (diff)
downloadnumpy-0767d38c8502aab52424ff9907ac1b63dc138597.tar.gz
Merge pull request #9322 from eric-wieser/ma-astype
BUG: np.ma.astype fails on 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 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__":