-
Notifications
You must be signed in to change notification settings - Fork 468
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
Expected truthiness of quantities with offsets #866
Comments
IMHO both proposed solutions are good (and either would be preferable to the current situation). Perhaps I would be inclined to raising |
That sounds like a good way forward, thanks! After looking to implement this, however, I'm now thinking it would make the most sense to wait until #764 (at least the scalar/sequence quantity split) is merged. |
With #764 and pydata/xarray#3238, in trying to implement proper
np.any
andnp.all
for Quantities, I got to wondering what the expected "truthiness" of a scalar quantity with offset should be. Right now, there seems to be no explicit behavior defined, so it falls back to the magnitude. This leads to the following type of result:Should this be the expected behavior?
At first glance, this kind of changing the truthiness of a quantity by changing the unit it is expressed in is a bit unsettling...making a small change like converting the unit doesn't seem like it should change the truthiness. In this case, I think there would need to be an explicit
__bool__
method that either converts to the non-offset equivalent or raises aValueError
due to ambiguity.However, I would also understand if the current behavior is what is expected, since thinking about it more, I would imagine that in most use cases checking for truthiness of a quantity reduces to checking for nonzero values. Also, I'm not sure what pint's stance on breaking existing but undocumented behavior is.
Either way, however, I think tests should be written for the expected behavior and it should be documented clearly (https://pint.readthedocs.io/en/0.9/nonmult.html). Once the expected behavior is decided upon, I'd be glad to put in a PR for that.
The text was updated successfully, but these errors were encountered: