[Numpy-discussion] recarray field names

Perry Greenfield perry at stsci.edu
Wed Mar 15 12:34:03 EST 2006


On Mar 15, 2006, at 3:20 PM, Erin Sheldon wrote:

> Hi all-
>
> I'm new to numpy and I'm slowly weening myself off of IDL. So far the
> experience has been very positive.
>
> I use recarrays a lot.  I often read these recarrays from fits files
> using pyfits (modified to work with numpy).  I find myself doing the
> following more than I would like:
>
> if 'TAG' in rec._coldefs.names:
>    ....
>
> It seems messy to be accessing this "hidden" attribute in this way.
> Is there a plan to add methods to more transparently do such things?
>
> e.g.
>
> def fieldnames():
>    return _coldefs.names
>
> def field_exists(fieldname):
>    return fieldname.upper() in _coldefs.names
>
> def field_index(fieldname):
>    if field_exists(fieldname):
>       return _coldefs.names.index(fieldname.upper())
>    else:
>       return -1  # or None maybe
>
> Thanks,
> Erin
>
You are right that this is messy. We would like to change this 
sometime. But we'd like to complete the transition to numpy first 
before doing that so it may be some months before we can (and it may 
not look quite like what you suggest). But your point is very valid.

Thanks, Perry





More information about the NumPy-Discussion mailing list