[Numpy-discussion] error message when using insufficient dtype dict

N. Volbers mithrandir42 at web.de
Mon Aug 21 15:07:12 CDT 2006


Hello everyone,

I had quite some trouble figuring out the _correct_ way to create 
heterogeneous arrays.

What I wanted to do was something like the following:

 >>>  numpy.array( [(0,0,0)], dtype={'names':['a','b','c'], 
'formats':['f4','f4','f4']})

This works fine. Now, let's do something wrong, e.g. leave out the 
'formats' specifier:

 >>> numpy.array( [(0,0,0)], dtype={'names':['a','b','c']})
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "/usr/lib/python2.4/site-packages/numpy/core/_internal.py", line 
53, in _usefields
    names, formats, offsets, titles = _makenames_list(adict)
  File "/usr/lib/python2.4/site-packages/numpy/core/_internal.py", line 
21, in _makenames_list
    raise ValueError, "entry not a 2- or 3- tuple"
ValueError: entry not a 2- or 3- tuple

This error message was totally unclear to me. After reading a little on 
the scipy wiki I finally realized that (maybe) numpy internally converts 
the dict with the names and the formats to a list of 2-tuples of the 
form (name, format). Since no formats were given, these 2-tuples were 
invalid.

I would suggest a check for the required dict keys and some meaningful 
error message like: "The dtype dictionary must at least contain the 
'names' and the 'formats' items."

Keep up the great work,

Niklas.





More information about the Numpy-discussion mailing list