-
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
Unexpected side effect using numpy trig functions #399
Comments
Thanks for reporting. We should not transform scalars to arrays.
|
I ran into this too.
This throws an error on the second
It took me a while to figure out what was going on. The call to I would expect any quantities that get passed into the numpy functions are left unmodified. Is |
A workaround is to pass copies of the quantity to the numpy functions using the
works as expected
|
Review after #905 |
Solved by #905 |
957: Add parameterized test for type immutability r=hgrecco a=jthielen As discussed in #925, this adds a parameterized test to verify that the internal type is not mutated under common operations (as encountered in #399, #481, #509, #622, #678). - [x] Closes #925, Closes #481 - [x] Executed ``black -t py36 . && isort -rc . && flake8`` with no errors - [x] The change is fully covered by automated unit tests - ~~Documented in docs/ as appropriate~~ - [x] Added an entry to the CHANGES file Co-authored-by: Jon Thielen <[email protected]>
I ran across this yesterday.
I type the following into a python REPL:
`
import numpy as np
import pint
ureg = pint.UnitRegistry()
Q_ = ureg.Quantity
theta = Q_(30, ureg.degrees)
type(theta.m) # returns int
s_theta = np.sin(theta)
type(theta.m) # returns numpy.ndarray
`
Printing theta, using comparisons, etc. doesn't show that anything has changed about it. I ran into trouble when I was saving an angle's magnitude to a JSON file, and json.dump complained that it didn't know how to write 'array(0.0)'. I worked backwards, and eventually isolated the point where the type of the angle's magnitude changed.
The text was updated successfully, but these errors were encountered: