[Numpy-discussion] np.void from 0d array + subclassing

David Goldsmith d.l.goldsmith@gmail....
Thu Dec 17 17:27:16 CST 2009

On Thu, Dec 17, 2009 at 2:11 PM, Pierre GM <pgmdevlist@gmail.com> wrote:
> Francesc, you're overestimating my knowledge of C... Can we stick to the Python implementation ?
> Here's the catch: IIUC, each individual element of a nD structured array is a void, provided the element can be accessed, ie that n>0. A 0D array cannot be indexed, so I don't know how

Unless someone can explain why it isn't, this sounds like an API
inconsistency, which in turn I would characterize as a bug.  But
others may disagree and/or explain it away...

> capture the object below. The sad trick I found was to do a .reshape(1)[0], but that looks really overkill...
>> The standard way (more or less) works for me:
>>>>> class myvoidclass(np.void):
>> ...     pass
>> ...
> David, what do you do w/ the __new__ of myvoidclass ? Just an empty class doesn't help me much, 'm'fraid.

Presumably, whatever you want (i.e., override it, calling the base
class constructor inside your __new__ if/when needed) - I've never
done this, so I have no reason to believe it would/should behave any
differently than any other Python subclass; your question merely
provoked me to check to see if the normal subclassing syntax did not
work for some reason, and since I found that it did, I thought I'd
post that result as a "data point".  Now, if you're generally
unfamiliar (but it doesn't sound like you are) with what to do with a
subclass' __new__, I'm sure someone else can more easily point you to
a reference for that issue.  Is there some reason you believe you have
to override __new__ differently in your use-case?


> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion@scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion

More information about the NumPy-Discussion mailing list