[Numpy-discussion] dtype names and titles

Colin J. Williams cjw at sympatico.ca
Mon Feb 13 19:55:02 CST 2006


Travis Oliphant wrote:

> 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.

Isn't it better to use the name as the identifier and the title as an 
external label? e.g. As a column heading when pretty-printing.

It seems to me that permitting either the name or the title as an object 
accessor is potentially confusing.

Colin W.

>
> 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
>
>
>
> -------------------------------------------------------
> This SF.net email is sponsored by: Splunk Inc. Do you grep through log 
> files
> for problems?  Stop!  Download the new AJAX search engine that makes
> searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
> http://sel.as-us.falkag.net/sel?cmd=lnk&kid=103432&bid=230486&dat=121642
> _______________________________________________
> Numpy-discussion mailing list
> Numpy-discussion at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/numpy-discussion
>





More information about the Numpy-discussion mailing list