diff options
author | Gerrit Holl <g.holl@reading.ac.uk> | 2015-12-03 16:34:52 +0000 |
---|---|---|
committer | Gerrit Holl <g.holl@reading.ac.uk> | 2015-12-03 16:52:44 +0000 |
commit | c8a09822c707f320d8c8ac242a8628de690a5899 (patch) | |
tree | 85ec076c07b70fb5493ee8bf30523699018f1f2d /numpy | |
parent | b3a8994a2a3c89c00ac4a95e01cd0888b72fd9af (diff) | |
download | numpy-c8a09822c707f320d8c8ac242a8628de690a5899.tar.gz |
BUG/TST: Fix #6760 by correctly describing mask on nested subdtypes
Fix #6760. In ma.core._recursive_make_descr, consider the case where a
subdtype does itself have named fields. This ensures the correct mask for
an array like `ma.zeros(2, dtype([("A", "(2,2)i1,(2,2)i1", (2,2))]))`.
Diffstat (limited to 'numpy')
-rw-r--r-- | numpy/ma/core.py | 2 | ||||
-rw-r--r-- | numpy/ma/tests/test_core.py | 7 |
2 files changed, 8 insertions, 1 deletions
diff --git a/numpy/ma/core.py b/numpy/ma/core.py index 9cc1a1272..ebc335a85 100644 --- a/numpy/ma/core.py +++ b/numpy/ma/core.py @@ -1248,7 +1248,7 @@ def _recursive_make_descr(datatype, newtype=bool_): # Is this some kind of composite a la (np.float,2) elif datatype.subdtype: mdescr = list(datatype.subdtype) - mdescr[0] = newtype + mdescr[0] = _recursive_make_descr(datatype.subdtype[0], newtype) return tuple(mdescr) else: return newtype diff --git a/numpy/ma/tests/test_core.py b/numpy/ma/tests/test_core.py index 2fdd00484..369138471 100644 --- a/numpy/ma/tests/test_core.py +++ b/numpy/ma/tests/test_core.py @@ -608,6 +608,13 @@ class TestMaskedArray(TestCase): control = np.array([(0, 1), (2, 0)], dtype=a['B'].dtype) assert_equal(test, control) + # test if mask gets set correctly (see #6760) + Z = numpy.ma.zeros(2, numpy.dtype([("A", "(2,2)i1,(2,2)i1", (2,2))])) + assert_equal(Z.data.dtype, numpy.dtype([('A', [('f0', 'i1', (2, 2)), + ('f1', 'i1', (2, 2))], (2, 2))])) + assert_equal(Z.mask.dtype, numpy.dtype([('A', [('f0', '?', (2, 2)), + ('f1', '?', (2, 2))], (2, 2))])) + def test_filled_w_f_order(self): # Test filled w/ F-contiguous array a = array(np.array([(0, 1, 2), (4, 5, 6)], order='F'), |