[Numpy-discussion] recarray field names

Travis Oliphant oliphant.travis at ieee.org
Mon Jul 10 23:19:44 CDT 2006

Erin Sheldon wrote:
> Just tested the lastest SVN and it works as advertised.  Thanks
> Travis.
> An unrelated question: why does this work for arrays but not recarrays?
> In [24]: mydescriptor = [('age',float64),('Nchildren',int8),('weight',float32)]   
> In [25]: a = array([(64,2,75.0),(25,0,60.0)], dtype=mydescriptor)
> In [26]: a = recarray([(64,2,75.0),(25,0,60.0)], dtype=mydescriptor)
> ---------------------------------------------------------------------------
> exceptions.TypeError                                 Traceback (most recent
> call last)
> /Users/esheldon/<ipython console> 
> TypeError: __new__() got an unexpected keyword argument 'dtype'
> I understand that I could use the formats and names keywords, but
> this seems a little inconsistent.  
Well there are a couple of reasons this doesn't work.

1) the recarray constructor is similar to the ndarray constructor. 
   Neither of these take list arguments as inputs.  So, while I've added 
dtype as the
   keyword for the formats input of the recarray constructor, the second 
example will still fail.

2) Even were you to use the rec.array function (which is analagous to 
the numpy.array function) to produce the error, it does not take a dtype 

   This is inconsistent.  But, the interface for the record array class 
came from numarray.  I tried to stay compatible with those functions so 
the numarray people would have an easier time adapting.

   Perhaps we should add a dtype keyword argument to all the 
constructors in numpy/core/records.py which over-rides the formats, 
names, and titles keywords so that you could do

a = rec.array([...], dtype=mine)

analgously to

a = array([...], dtype=mine)


More information about the Numpy-discussion mailing list