-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Quantity.__array_ufunc__ should return NotImplemented for Time instances (and other classes that it does not know about) #10776
Comments
@mhvk do you think this can be labeled as "good first issue"? |
Hmm, not sure. It does need a bit of thought. In particular, to ensure the path of other quantities remains fast, i.e., it cannot just be an upfront check that any of the arguments is a |
So I took a look at The problem appears to be this method takes objects with a non-defined 'unit' property and ultimately treats them as How does the team feel about such an approach? |
@Iamsoto - it would work, but I feel it puts the burden in the wrong place - really, p.s. The present implementation is a bit too keen on duck typing, I fear. Generally, duck typing is a good thing, but not for things where one deals with the interaction of multiple classes, all of which might be able to make things work. |
Actually, thinking more about this: what would also solve this is if EDIT (2021-jan-5): that does not help, of course, that is the whole issue! So, will need to be smarter in |
In #10653 (comment), @Antetokounpo found that if
Time.__array_ufunc__
is defined,timedelta * dimensionless_quantity
fails to work correctly. This is becauseQuantity.__array_ufunc__
does not correctly returnNotImplemented
:Right now, this bug is hidden by the fact that
Time
does not define__array_ufunc__
, which means that__array_priority__
is used, which is higher thanQuantity.__array_priority__
and henceq * dt
gets done byTimeDelta.__rmul__
.EDIT: this is a more general problem also for any class that defines a
unit
attribute but would likeQuantity
not to assume it understands it. Understanding should be opt-in somehow...The text was updated successfully, but these errors were encountered: