[Numpy-discussion] Proposal: add ndarray.keys() to return dtype.names

Benjamin Root ben.root at ou.edu
Tue Sep 30 09:19:49 EDT 2014


I am also +1. I have already used structured arrays to do keyword-based
string formatting. This makes sense as well. Would this enable keyword
argument expansion?

On Tue, Sep 30, 2014 at 7:29 AM, Eelco Hoogendoorn <
hoogendoorn.eelco at gmail.com> wrote:

> Sounds fair to me. Indeed the ducktyping argument makes sense, and I have
> a hard time imagining any namespace conflicts or other confusion. Should
> this attribute return none for non-structured arrays, or simply be
> undefined?
>
> On Tue, Sep 30, 2014 at 12:49 PM, John Zwinck <jzwinck at gmail.com> wrote:
>
>> I first proposed this on GitHub:
>> https://github.com/numpy/numpy/issues/5134 ; jaimefrio requested that
>> I bring it to this list for discussion.
>>
>> My proposal is to add a keys() method to NumPy's array class ndarray.
>> The behavior would be to return self.dtype.names, i.e. the "column
>> names" for a structured array (and None when dtype.names is None,
>> which it is for pure numeric arrays without named columns).
>>
>> I originally proposed to add a values() method also, but I am tabling
>> that for now so we needn't discuss it in this thread.
>>
>> The motivation is to enhance the ability to use duck typing with NumPy
>> arrays, Python dicts, and other types like Pandas DataFrames, h5py
>> Files, and more.  It's a fairly common thing to want to get the "keys"
>> of a container, where "keys" is understood to be a sequence of values
>> one can pass to __getitem__(), and this is exactly what I'm aiming at.
>>
>> Thoughts?
>>
>> John Zwinck
>> _______________________________________________
>> NumPy-Discussion mailing list
>> NumPy-Discussion at scipy.org
>> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>>
>
>
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20140930/908baeb2/attachment.html>


More information about the NumPy-Discussion mailing list