[Numpy-discussion] Using numpy's flatten_dtype with structured dtypes that have titles

Stéfan van der Walt stefan@sun.ac...
Mon Aug 23 16:26:25 CDT 2010

On 23 August 2010 17:09, Pierre GM <pgmdevlist@gmail.com> wrote:
>> On the other hand, if I remove the titles from the dtype, the code works with or without the monkey patch. Without the titles, the dtype looks like:
>> dtype1 = numpy.dtype([("Current","f8"),("Voltage","f8"),("Power","f8")])
>> Thanks very much for your help with this issue.
>> Emma
> Emma,
> Please open a ticket. That's a bug in flatten_dtype, which cannot handle titles in the dtype (as I never used titles, I forgot they were there...). I'll try to take care of that ASAP.

Not sure, but the fix may be as simple as

diff --git a/numpy/lib/_iotools.py b/numpy/lib/_iotools.py
index c9d8104..3a2a62b 100644
--- a/numpy/lib/_iotools.py
+++ b/numpy/lib/_iotools.py
@@ -132,7 +132,8 @@ def flatten_dtype(ndtype, flatten_base=False):
         types = []
         for field in names:
-            (typ, _) = ndtype.fields[field]
+            fieldinfo = ndtype.fields[field]
+            typ = fieldinfo[0]
             flat_dt = flatten_dtype(typ, flatten_base)
         return types


More information about the NumPy-Discussion mailing list