[Numpy-discussion] bug !? dtype type_descriptor does not accept zero length tuple

Sebastian Haase haase at msg.ucsf.edu
Wed Aug 9 16:02:14 CDT 2006

I have a problem with record array type descriptor.
With numarray this used to work.
My records made of  n integers and m floats.  So I used to be able specify
formats="%di4,%df4"%(self.numInts,self.numFloats) in numarray which would 
translate to 
byteorder = self.isByteSwapped and '>' or '<'
type_descr = [("int",   "%s%di4" %(byteorder,self.numInts)),
                      ("float", "%s%df4" %(byteorder,self.numFloats))]

The problem occurs when numInts or numFloats is zero !?
Could it numpy be changed to silectly accept this case
Here is the complete traceback + some debug info:

'>0i4'Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "/home/haase/PrLinN/Priithon/Mrc.py", line 56, in bindFile
    a = Mrc(fn, mode)
  File "/home/haase/PrLinN/Priithon/Mrc.py", line 204, in __init__
  File "/home/haase/PrLinN/Priithon/Mrc.py", line 271, in doExtHdrMap
    self.extHdrArray.dtype = type_descr
  File "/home/haase/qqq/lib/python/numpy/core/records.py", line 194, in 
    return object.__setattr__(self, attr, val)
TypeError: invalid data-type for array
>>> U.debug()
> /home/haase/qqq/lib/python/numpy/core/records.py(196)__setattr__()
-> pass
(Pdb) l
192         def __setattr__(self, attr, val):
193             try:
194                 return object.__setattr__(self, attr, val)
195             except AttributeError: # Must be a fieldname
196  ->             pass
197             fielddict = sb.ndarray.__getattribute__(self,'dtype').fields
198             try:
199                 res = fielddict[attr][:2]
200             except (TypeError,KeyError):
201                 raise AttributeError, "record array has no attribute %s" % 
(Pdb) p val
[('int', '>0i4'), ('float', '>2f4')]
(Pdb) p attr

Sebastian Haase

More information about the Numpy-discussion mailing list