[Numpy-svn] r6131 - in trunk/numpy/ma: . tests
numpy-svn at scipy.org
numpy-svn at scipy.org
Tue Dec 2 03:50:13 EST 2008
Author: pierregm
Date: 2008-12-02 02:50:11 -0600 (Tue, 02 Dec 2008)
New Revision: 6131
Modified:
trunk/numpy/ma/core.py
trunk/numpy/ma/tests/test_core.py
Log:
* Fixed make_mask_descr for dtype w/ composite names, like [(('A','B'), float)]
Modified: trunk/numpy/ma/core.py
===================================================================
--- trunk/numpy/ma/core.py 2008-12-02 02:40:22 UTC (rev 6130)
+++ trunk/numpy/ma/core.py 2008-12-02 08:50:11 UTC (rev 6131)
@@ -800,12 +800,19 @@
"""
def _make_descr(datatype):
"Private function allowing recursion."
+ datatype = np.dtype(datatype)
# Do we have some name fields ?
- names = datatype.names
- if names:
+ if datatype.names:
descr = []
- for name in names:
- (ndtype, _) = datatype.fields[name]
+ # !!!: If one of the fieldnames is a tuple, only its last element
+ # !!!: is listed in datatype.names: we need to take datatype.descr.
+ for name in (_[0] for _ in datatype.descr):
+ # Take the last element of the tuple as key for datatype.fields
+ if isinstance(name, tuple):
+ # datatype.fields[name] is a tuple of 2 or 3 element...
+ ndtype = datatype.fields[name[-1]][0]
+ else:
+ ndtype = datatype.fields[name][0]
descr.append((name, _make_descr(ndtype)))
return descr
# Is this some kind of composite a la (np.float,2)
Modified: trunk/numpy/ma/tests/test_core.py
===================================================================
--- trunk/numpy/ma/tests/test_core.py 2008-12-02 02:40:22 UTC (rev 6130)
+++ trunk/numpy/ma/tests/test_core.py 2008-12-02 08:50:11 UTC (rev 6131)
@@ -2328,29 +2328,33 @@
def test_make_mask_descr(self):
"Test make_mask_descr"
+ # Flexible
ntype = [('a',np.float), ('b',np.float)]
test = make_mask_descr(ntype)
assert_equal(test, [('a',np.bool),('b',np.bool)])
- #
+ # Standard w/ shape
ntype = (np.float, 2)
test = make_mask_descr(ntype)
assert_equal(test, (np.bool,2))
- #
+ # Standard standard
ntype = np.float
test = make_mask_descr(ntype)
assert_equal(test, np.dtype(np.bool))
- #
+ # Nested
ntype = [('a', np.float), ('b', [('ba', np.float), ('bb', np.float)])]
test = make_mask_descr(ntype)
control = np.dtype([('a', 'b1'), ('b', [('ba', 'b1'), ('bb', 'b1')])])
assert_equal(test, control)
- #
+ # Named+ shape
ntype = [('a', (np.float, 2))]
test = make_mask_descr(ntype)
assert_equal(test, np.dtype([('a', (np.bool, 2))]))
+ # 2 names
+ ntype = [(('A', 'a'), float)]
+ test = make_mask_descr(ntype)
+ assert_equal(test, np.dtype([(('A', 'a'), bool)]))
-
def test_make_mask(self):
"Test make_mask"
# w/ a list as an input
More information about the Numpy-svn
mailing list