[Numpy-discussion] RecArray.tolist() suggestion
Colin J. Williams
cjw at sympatico.ca
Fri Jul 16 19:46:09 EDT 2004
Paul Barrett wrote:
> Russell E Owen wrote:
>
>>> A Divendres 16 Juliol 2004 02:21, Colin J. Williams va escriure:
>>>
>>>> To allow for multi-word column names, assignment could replace a
>>>> space
>>>> by an underscore
>>>> and, in retrieval, the reverse could be done - ie. underscore
>>>> would be
>>>> banned for a column name.
>>>
>>>
>>>
>>> That's not so easy. What about other chars like '/&%@$()' that
>>> cannot be
>>> part of python names? Finding a biunivocal map between them and allowed
>>> chars would be difficult (if possible at all). Besides, the resulting
>>> colnames might become a real mess.
>>
>>
>>
>> Personally, I think the idea of allowing access to fields via
>> attributes is fatally flawed. The problems raised (non-obvious
>> mapping between field names with special characters and allowable
>> attribute names and also the collision with existing instance
>> variable and method names) clearly show it would be forced and
>> non-pythonic.
>
>
> +1
Paul,
Below, I've appended my response to Francesc's 08:36 message, it was
copied to the list
but does not appear in the archive.
>
> It also make it difficult to do the following:
>
> a = item[:10, ('age', 'surname', 'firstname')]
>
> where field (or column) 1 is 'firstname, field 2 is 'surname', and
> field 10 is 'age'.
>
> -- Paul
Could you clarify what you have in mind here please? Is this a proposed
extension to records.py, as it exists in version 1.0?
Colin W.
------------------------------------------------------------------------
Yes, if the objective is to include special characters or facilitate
multi-lingual columns names and
it probably should be, then my suggestion is quite inadequate.
Perhaps there could be a simple name -> column number mapping in place
of _names. References
to a column, or a field in a record, could then be through this dictionary.
Basic access to data in a record would be by position number, rather
than name, but the dictionary
would facilitate access by name.
Data could be referenced either through the column name: r1.c2[1] or
through the record r1[1].c2, with the possibility that the index is
multi-dimensional in either case.
Colin W.
More information about the NumPy-Discussion
mailing list