summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
authorpierregm <pierregm@localhost>2009-12-18 15:35:08 +0000
committerpierregm <pierregm@localhost>2009-12-18 15:35:08 +0000
commit2e28be893dd2a8180505683f3aa0cc72ebe0bc47 (patch)
tree55e5fab55202b7c3047329ecb5e647fecb90ff1a /numpy
parentbc2232b84d2c5e50826f715507fa23d70c6c8718 (diff)
downloadnumpy-2e28be893dd2a8180505683f3aa0cc72ebe0bc47.tar.gz
* fix .tolist() for mvoid objects (bug #1330)
Diffstat (limited to 'numpy')
-rw-r--r--numpy/ma/core.py21
-rw-r--r--numpy/ma/tests/test_core.py4
2 files changed, 23 insertions, 2 deletions
diff --git a/numpy/ma/core.py b/numpy/ma/core.py
index 938aa8db3..83bff9516 100644
--- a/numpy/ma/core.py
+++ b/numpy/ma/core.py
@@ -5225,10 +5225,10 @@ class MaskedArray(ndarray):
# Structured array .............
names = self.dtype.names
if names:
- result = self.astype([(_, object) for _ in names])
+ result = self._data.astype([(_, object) for _ in names])
for n in names:
result[n][_mask[n]] = None
- return result.data.tolist()
+ return result.tolist()
# Standard arrays ...............
if _mask is nomask:
return [None]
@@ -5523,6 +5523,23 @@ class mvoid(MaskedArray):
"""
return asarray(self).filled(fill_value)[()]
+ def tolist(self):
+ """
+ Transforms the object into a list
+ """
+ _mask = self._mask
+ if _mask is nomask:
+ return self._data.tolist()
+ result = []
+ for (d, m) in zip(self._data, self._mask):
+ if m:
+ result.append(None)
+ else:
+ result.append(d)
+ return tuple(result)
+
+
+
#####--------------------------------------------------------------------------
#---- --- Shortcuts ---
#####---------------------------------------------------------------------------
diff --git a/numpy/ma/tests/test_core.py b/numpy/ma/tests/test_core.py
index fea0ac0d4..6b21ae015 100644
--- a/numpy/ma/tests/test_core.py
+++ b/numpy/ma/tests/test_core.py
@@ -2332,6 +2332,10 @@ class TestMaskedArrayMethods(TestCase):
dtype=[('a', int), ('b', int)])
test = a.tolist()
assert_equal(test, [[1, None], [3, 4]])
+ # ... on mvoid
+ a = a[0]
+ test = a.tolist()
+ assert_equal(test, [1, None])
def test_toflex(self):