You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
np.abs(DeltaTime(dts)) returns object np.array not DeltaTime(abs(dts)) #10653
I've written a quick and dirty implementation of __array_ufunc__ and although it fixes the problems np.add, np.abs,, etc., it creates a whole lot of new ones. For example:
The expected behavior in this case would be that the returned result is a TimeDelta and not a Quantity. But I've noticed that this happens only if __array_ufunc__ is defined, even if it's only a simple pass (and it doesn't get called anyway). I haven't been able to track down why it happens though.
So it seems that if we're going to implement __array_ufunc__ to fix this issue, we also need to modify how Quantity objects (and maybe others) interact with TimeDelta.
@Antetokounpo - Right now, without Time.__array_ufunc__, the quantity version never gets called because Time.__array_priority__ is defined and is higher than Quantity.__array_priority__. But if you do define Time.__array_ufunc__, then the priorities no longer get checked.
But you did find a bug: Quantity.__array_ufunc__ should returning NotImplemented for any Time input, as it does not know how to deal with those. I raised #10776.
Activity
mhvk commentedon Aug 13, 2020
Arrgghh. To get this to work we need to implement
__array_ufunc__- not super-hard.Note that
absdoes work (since that just uses the method):mhvk commentedon Aug 13, 2020
p.s. Right now, for the same reason,
np.add,np.subtract, etc.,do not work eithercreate object arrays as well.Antetokounpo commentedon Sep 27, 2020
I've written a quick and dirty implementation of
__array_ufunc__and although it fixes the problemsnp.add, np.abs,, etc., it creates a whole lot of new ones. For example:The expected behavior in this case would be that the returned result is a
TimeDeltaand not aQuantity. But I've noticed that this happens only if__array_ufunc__is defined, even if it's only a simplepass(and it doesn't get called anyway). I haven't been able to track down why it happens though.So it seems that if we're going to implement
__array_ufunc__to fix this issue, we also need to modify howQuantityobjects (and maybe others) interact withTimeDelta.mhvk commentedon Sep 27, 2020
@Antetokounpo - Right now, without
Time.__array_ufunc__, the quantity version never gets called becauseTime.__array_priority__is defined and is higher thanQuantity.__array_priority__. But if you do defineTime.__array_ufunc__, then the priorities no longer get checked.But you did find a bug:
Quantity.__array_ufunc__should returningNotImplementedfor anyTimeinput, as it does not know how to deal with those. I raised #10776.mhvk commentedon Sep 28, 2020
Note that @maxnoe has also started to implement
Time.__array_ufunc__- see #10272.