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

Sebastian Wagner sebix at sebix.at
Thu Oct 2 06:27:26 EDT 2014


So, for non-structured arrays, the consens is an Exception. The question
is, which one.
AttributeError would be fully backwards compatible. Existing code checks
for the method and if it exists, the object has fields.
ValueError would make more sense, as the value - the array - is in wrong
format/structure/type.

regards,

On 2014-10-01 16:47, Eelco Hoogendoorn wrote:
> Ah yes; you can use..
> 
> from types import MethodType
> 
> ...to dynamically add methods to specific instances of a type. This
> may be cleaner or more pythonic than performing a check within the
> method, I dunno.
> 
> On Wed, Oct 1, 2014 at 4:41 PM, Benjamin Root <ben.root at ou.edu> wrote:
> 
>> Actually, if I remember correctly, special methods show up in the
>> ndarray object when the dtype is datetime64, right?
>> 
>> On Wed, Oct 1, 2014 at 10:13 AM, Eelco Hoogendoorn
>> <hoogendoorn.eelco at gmail.com> wrote:
>> 
>> Well, the method will have to be present on all ndarrays, since
>> structured arrays do not have a different type from regular arrays,
>> only a different dtype. Thus the attribute has to be present
>> regardless, but some Exception will have to be raised depending on
>> the dtype, to make it quack like the kind of duck it is, so to
>> speak. Indeed it seems like an atypical design pattern; but I don't
>> see a problem with it.
>> 
>> On Wed, Oct 1, 2014 at 4:08 PM, John Zwinck <jzwinck at gmail.com>
>> wrote:
>> 
>> On 1 Oct 2014 04:30, "Stephan Hoyer" <shoyer at gmail.com> wrote:
>>> 
>>> On Tue, Sep 30, 2014 at 1:22 PM, Eelco Hoogendoorn
>> <hoogendoorn.eelco at gmail.com> wrote:
>>>> 
>>>> 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.
>>> 
>>> Indeed, I think we do agree. The attribute can simply be missing
>> (e.g., accessing it raises AttributeError) for non-structured
>> arrays.
>> 
>> I'm generally fine with this, though I would like to know if there
>> is precedent for methods being present on structured arrays only.
>> Even if there is no precedent I am still OK with the idea, I just
>> think we should understand if how novel this will be.
>> _______________________________________________
>> NumPy-Discussion mailing list
>> NumPy-Discussion at scipy.org
>> http://mail.scipy.org/mailman/listinfo/numpy-discussion [1]
>> 
>> _______________________________________________
>> NumPy-Discussion mailing list
>> NumPy-Discussion at scipy.org
>> http://mail.scipy.org/mailman/listinfo/numpy-discussion [1]
> 
> _______________________________________________
>  NumPy-Discussion mailing list
>  NumPy-Discussion at scipy.org
>  http://mail.scipy.org/mailman/listinfo/numpy-discussion [1]
> 
> 
> 
> Links:
> ------
> [1] 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



More information about the NumPy-Discussion mailing list