[Numpy-discussion] Automatic custom dtype

Charles R Harris charlesr.harris at gmail.com
Fri Jun 28 12:33:48 EDT 2013

On Fri, Jun 28, 2013 at 5:27 AM, Richard Hattersley
<rhattersley at gmail.com>wrote:

> On 21 June 2013 19:57, Charles R Harris <charlesr.harris at gmail.com> wrote:
> > You could check the numpy/core/src/umath/test_rational.c.src code to see
> if
> > you are missing something.
> In v1.7+ the difference in behaviour between my code and the rational
> test case is because my scalar type doesn't subclass np.generic (aka.
> PyGenericArrType_Type).
> In v1.6 this requirement doesn't exist ... mostly ... In other words,
> it works as long as the supplied scalars are contained within a
> sequence.
> So:
>     np.array([scalar]) => np.array([scalar], dtype=my_dtype)
> But:
>     np.array(scalar) => np.array(scalar, dtype=object)

So the scalar case (0 dimensional array) doesn't work right. Hmm, what
happens when you index the first array? Does subclassing the generic type
work in 1.6?

My impression is that subclassing the generic type should be required, but
I don't see where it is documented :( Anyway, what is the problem with the
third party code? Is there no chance that you can get hold of it to fix it?

> For one of my scalar/dtype combos I can easily workaround the 1.7+
> issue by just adding the subclass relationship. But another of my
> dtypes is wrapping a third-party type so I can't modify the subclass
> relationship. :-(
> So I guess I have three questions.
> Firstly, is there some cunning workaround when defining a dtype for a
> third-party type?
> Secondly, is the subclass-generic requirement in v1.7+ desirable
> and/or intended? Or just an accidental regression?
> And thirdly, assuming it's desirable to remove the subclass-generic
> requirement, would it also make sense to make it work for scalars
> which are not within a sequence?
> NB. If we decide there's some work which needs doing here, then I
> should be able to put time on it.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20130628/1c926683/attachment.html>

More information about the NumPy-Discussion mailing list