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

Eelco Hoogendoorn hoogendoorn.eelco at gmail.com
Tue Sep 30 16:22:07 EDT 2014


On more careful reading of your words, I think we agree; indeed, if keys()
is present is should return an iterable; but I don't think it should be
present for non-structured arrays.

On Tue, Sep 30, 2014 at 10:21 PM, Eelco Hoogendoorn <
hoogendoorn.eelco at gmail.com> wrote:

> So a non-structured array should return an empty list/iterable as its
> keys? That doesn't seem right to me, but perhaps you have a compelling
> example to the contrary.
>
> I mean, wouldn't we want the duck-typing to fail if it isn't a structured
> array? Throwing an attributeError seems like the best thing to do, from a
> duck-typing perspective.
>
> On Tue, Sep 30, 2014 at 8:05 PM, Stephan Hoyer <shoyer at gmail.com> wrote:
>
>> I like this idea. But I am -1 on returning None if the array is
>> unstructured. I expect .keys(), if present, to always return an iterable.
>>
>> In fact, this would break some of my existing code, which checks for the
>> existence of "keys" as a way to do duck typed checks for dictionary like
>> objects (e.g., including pandas.DataFrame):
>> https://github.com/xray/xray/blob/v0.3/xray/core/utils.py#L165
>>
>> _______________________________________________
>> 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/83fb2563/attachment.html>


More information about the NumPy-Discussion mailing list