[Numpy-discussion] problem with ndarray attributes

Travis Oliphant oliphant at ee.byu.edu
Mon Mar 27 14:15:00 CST 2006

Christopher Hanley wrote:

> Hi Travis,
> I have run across a feature in numpy which I am not sure how to 
> handle.  One of the new features of the ndarray is that named fields 
> can be accessed as attributes.  So, if a user created a recarray with 
> fields named "address", "phone", and "names" they would be able to 
> access all of the names in the recarray objects with 
> "recarrayObject.names".
> I have found that this can cause problems when a user creates a table 
> with a field name that happen to coincide with an existing class 
> attribute or method.  In particular, I am having a problem in pyfits 
> where a user has a table with a column named "field".  This column 
> name is causing an attribute "field" to be created that overrides the 
> existing class field method.
> It would seem to me that existing class methods and attributes should 
> take precedence over the attributes created to correspond to column 
> names.  Is there a way to implement this behavior in ndarray?
Now that I've written that I think the class methods and attributes 
should come first, I should mention, however, that a library writer 
could write


to make sure that the method


always gets called.   This seems like quite a burden to force on library 
writers, though.  I'd rather have users be aware of what they are using 
as field names since the methods and attributes on arrays should not be 
changing excessively.


More information about the Numpy-discussion mailing list