[Numpy-discussion] dtype names and titles

Travis Oliphant oliphant.travis at ieee.org
Sat Feb 11 14:24:04 CST 2006


N. Volbers wrote:

> I continue to learn all about the heterogeneous arrays...
>
> When I was reading through the records.py code I discovered that 
> besides the 'names' and 'formats' for the fields of a numpy array you 
> can also specify 'titles'. Playing around with this feature I 
> discovered a bug:
>
> >>> import numpy
> >>> mydata = [(1,1), (2,4), (3,9)]
> >>> mytype = {'names': ['col1','col2'], 'formats':['i2','f4'], 
> 'titles': ['col2', 'col1']}
> >>> b = numpy.array( mydata, dtype=mytype)
> >>> print b
> [(1.0, 1.0) (4.0, 4.0) (9.0, 9.0)]
>
> This seems to be caused by the fact that you can access a field by 
> both the name and the field title. Why would you want to have two 
> names anyway?

This lets you use attribute look up on the names but have the titles be 
the "true name" of the field.

I've fixed this in SVN, so that it raises an error when the titles have 
the same names as the columns.

Thanks for the test.


-Travis





More information about the Numpy-discussion mailing list