[Numpy-discussion] recarray field names

Travis Oliphant oliphant at ee.byu.edu
Mon Jul 10 14:04:07 CDT 2006

John Parejko wrote:

>Howdy!  I just wanted to voice my agreement with this statment by Erin Sheldon:
> > I brought up the issue a while back of having a simple way to
> > access the field names of an array. The quick summary: accessing
> > field names has some oddness that needs cleaning up.
>Sometimes a['name'], sometimes a.field('name').  I vastly prefer the first 
>version; it has become my favored way of dealing with my FITS and ASCII 
>data.  But using the bracket notation sometimes gives an error, and I 
>haven't quite figured out what the circumstances are.
>Also, "for name in a.dtype.fields:" or "for name in a.fields:" would be 
>very, very handy.
>Could this sort of thing get put in before the beta (or is it already in, 
>and I missed the boat, again?).
It's actually there already.   The issue at hand is that the fields 
dictionary contains an additional member keyed by a -1.  This odd-ball 
entry in the dictionary is to obtain an "ordered" list of the fields.  
The order is determined by the offset.

This is a warty situation but the functionality is there.

Probably a better solution is to add a names attribute to the dtype 
object that returns the ordered list.  In C, the PyArray_Descr structure 
would grow an additional names member that contains the ordered list of 
names instead of sticking it as a -1 key entry in the fields dictionary 
which was and is a hack.

Let's schedule this for pre 1.0 beta


More information about the Numpy-discussion mailing list