[Numpy-discussion] Automatic custom dtype

Richard Hattersley rhattersley at gmail.com
Fri Jun 28 06:27:49 EDT 2013

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.

In v1.6 this requirement doesn't exist ... mostly ... In other words,
it works as long as the supplied scalars are contained within a
    np.array([scalar]) => np.array([scalar], dtype=my_dtype)
    np.array(scalar) => np.array(scalar, dtype=object)

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.


More information about the NumPy-Discussion mailing list