-
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
unintuitive behaviour interacting with numpy scalars #900
Comments
I think this is a bigger issue in general with NumPy's deferring to pint for operator precedence not working properly. The following code (with arrays) demonstrates the same issue: import pint, numpy
si = pint.UnitRegistry()
a = numpy.array([0, 1, 2])
b = 10. * si.gram / si.kilogram
print(a + b, "vs.", b + a)
It looks like some more subtle debugging of why the bare NumPy array/scalar is not treated as dimensionless in the first example is need. |
I guess "unintuitive behaviour" is the British way to say "buggy"... Even more generally, the problem seems to be that (numpy array) + (pint array) is a valid operation regardless of the dimensions which is surely a bug: import pint, numpy
si = pint.UnitRegistry()
numpy.asarray([1.0, 2.0]) + 10.* si.gram # [11.0, 12.0] gram
1.0 + 10.0 * si.gram # pint.errors.DimensionalityError: Cannot convert from 'gram' to 'dimensionless' One could argue that the first behaviour (add to the magnitude) is proper (I do not think so), but surely one cannot argue that floats and ndarrays should behave differently. Looking at the definition in pint ( Line 719 in e6ae929
|
This should be resolved with #905 (see test added below): pint/pint/testsuite/test_numpy.py Lines 327 to 331 in 43fbae2
@Michaeldz36 and @Tigraan would you be able to confirm if this is resolved for you on the current master branch? |
Closing. @Michaeldz36 and @Tigraan , feel free to write back if needed. |
The text was updated successfully, but these errors were encountered: