diff options
author | Marten van Kerkwijk <mhvk@astro.utoronto.ca> | 2014-07-16 11:03:43 +0200 |
---|---|---|
committer | Marten van Kerkwijk <mhvk@astro.utoronto.ca> | 2014-07-17 23:37:16 +0200 |
commit | 4ed00c7e3b3206d4abf5536d4d0014fb08d22bc2 (patch) | |
tree | 170f5fcb3adb19faeefe4bea4434a9e7a1a39ffa | |
parent | 88cf0e4f6d722b12f2d57e3acb6452d6a015cc93 (diff) | |
download | numpy-4ed00c7e3b3206d4abf5536d4d0014fb08d22bc2.tar.gz |
BUG Make ma[row][rec] setter work by avoiding copy in mvoid.__new__
-rw-r--r-- | numpy/ma/core.py | 5 | ||||
-rw-r--r-- | numpy/ma/tests/test_core.py | 11 |
2 files changed, 11 insertions, 5 deletions
diff --git a/numpy/ma/core.py b/numpy/ma/core.py index 5c566b92c..b78d9ec7f 100644 --- a/numpy/ma/core.py +++ b/numpy/ma/core.py @@ -5594,9 +5594,8 @@ class mvoid(MaskedArray): """ # def __new__(self, data, mask=nomask, dtype=None, fill_value=None, - hardmask=False): - dtype = dtype or data.dtype - _data = np.array(data, dtype=dtype) + hardmask=False, copy=False, subok=True): + _data = np.array(data, copy=copy, subok=subok, dtype=dtype) _data = _data.view(self) _data._hardmask = hardmask if mask is not nomask: diff --git a/numpy/ma/tests/test_core.py b/numpy/ma/tests/test_core.py index e6f659041..595c52898 100644 --- a/numpy/ma/tests/test_core.py +++ b/numpy/ma/tests/test_core.py @@ -815,7 +815,7 @@ class TestMaskedArrayArithmetic(TestCase): res = count(ott) self.assertTrue(res.dtype.type is np.intp) assert_equal(3, res) - + ott = ott.reshape((2, 2)) res = count(ott) assert_(res.dtype.type is np.intp) @@ -3523,8 +3523,15 @@ class TestMaskedFields(TestCase): assert_equal_records(a[-2]._mask, a._mask[-2]) def test_setitem(self): - # Issue 2403 + # Issue 4866: check that one can set individual items in [record][col] + # and [col][record] order ndtype = np.dtype([('a', float), ('b', int)]) + ma = np.ma.MaskedArray([(1.0, 1), (2.0, 2)], dtype=ndtype) + ma['a'][1] = 3.0 + assert_equal(ma['a'], np.array([1.0, 3.0])) + ma[1]['a'] = 4.0 + assert_equal(ma['a'], np.array([1.0, 4.0])) + # Issue 2403 mdtype = np.dtype([('a', bool), ('b', bool)]) # soft mask control = np.array([(False, True), (True, True)], dtype=mdtype) |