[SciPy-Dev] [Numpy-discussion] Baffling error: ndarray += csc_matrix -> "ValueError: setting an array element with a sequence"

Pauli Virtanen pav@iki...
Fri Sep 27 15:54:15 CDT 2013


27.09.2013 23:33, Nathaniel Smith kirjoitti:
[clip]
> Great! I guess solving this somehow will be release-critical, to avoid
> a regression in this case when __numpy_ufunc__ gets released. If the
> solution should be in scipy, I guess we should file the bug there?

It's release-critical, but the feature is added only in Numpy 1.9 and
Scipy 0.14.0, so there's several months time to iron out the bugs here.

Scipy bug: https://github.com/scipy/scipy/issues/2938
Numpy bug: https://github.com/numpy/numpy/issues/3812

[clip]
> I'm a little uncertain about the "swallow all TypeErrors" aspect of
> this -- e.g. this could have really weird effects for object arrays,
> where ufuncs may raise arbitrary user exceptions.

A second alternative here would be to pass an additional internal-use
keyword argument to the generic ufunc that instructs it to return
NotImplemented rather than raising errors.

This could also make the ufuncs better Python citizens by stopping them
from littering NotImplemented around.

> One possibility in the long run is to just say, if you want to
> override ndarray __iadd__ or whatever, then you have to use
> __numpy_ufunc__. Not really much point in having *two* sets of
> implementations of the NotImplemented dance for the same operation.

I think __numpy_ufunc__ breaking the default Python __*__ binary op
system is a bit nasty, and would be better avoided if possible.

-- 
Pauli Virtanen



More information about the SciPy-Dev mailing list