diff options
-rw-r--r-- | numpy/ma/core.py | 5 | ||||
-rw-r--r-- | numpy/ma/tests/test_core.py | 20 |
2 files changed, 24 insertions, 1 deletions
diff --git a/numpy/ma/core.py b/numpy/ma/core.py index 25050f651..de8512831 100644 --- a/numpy/ma/core.py +++ b/numpy/ma/core.py @@ -5387,7 +5387,9 @@ class MaskedArray(ndarray): self.dtype, self.flags.fnc, self._data.tostring(cf), + #self._data.tolist(), getmaskarray(self).tostring(cf), + #getmaskarray(self).tolist(), self._fill_value, ) return state @@ -5546,7 +5548,8 @@ class mvoid(MaskedArray): if m: result.append(None) else: - result.append(d) + # .item() makes sure we return a standard Python object + result.append(d.item()) return tuple(result) diff --git a/numpy/ma/tests/test_core.py b/numpy/ma/tests/test_core.py index ba3a23040..700f99ba2 100644 --- a/numpy/ma/tests/test_core.py +++ b/numpy/ma/tests/test_core.py @@ -396,6 +396,13 @@ class TestMaskedArray(TestCase): test = cPickle.loads(cPickle.dumps(b)) assert_equal(test, b) +# def test_pickling_oddity(self): +# "Test some pickling oddity" +# import cPickle +# a = array([{'a':1}, {'b':2}, 3], dtype=object) +# test = cPickle.loads(cPickle.dumps(a)) +# assert_equal(test, a) + def test_single_element_subscript(self): "Tests single element subscripts of Maskedarrays." a = array([1, 3, 2]) @@ -2350,6 +2357,19 @@ class TestMaskedArrayMethods(TestCase): test = a.tolist() assert_equal(test, [1, None]) + def test_tolist_specialcase(self): + "Test mvoid.tolist: make sure we return a standard Python object" + a = array([(0, 1), (2, 3)], dtype=[('a', int), ('b', int)]) + # w/o mask: each entry is a np.void whose elements are standard Python + for entry in a: + for item in entry.tolist(): + assert(not isinstance(item, np.generic)) + # w/ mask: each entry is a ma.void whose elements should be standard Python + a.mask[0] = (0, 1) + for entry in a: + for item in entry.tolist(): + assert(not isinstance(item, np.generic)) + def test_toflex(self): "Test the conversion to records" |