Skip to content
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

Incorrect answers with numpy ufuncs and the out keyword #644

Closed
ngoldbaum opened this issue May 29, 2018 · 6 comments
Closed

Incorrect answers with numpy ufuncs and the out keyword #644

ngoldbaum opened this issue May 29, 2018 · 6 comments
Labels
numpy Numpy related bug/enhancement

Comments

@ngoldbaum
Copy link

Consider the following example:

import numpy as np
from pint import UnitRegistry

u = UnitRegistry()

a = [1, 2, 3]*u.g
b = [1, 2, 3]*u.kg
out = np.zeros(3)

print(np.add(a, b, out=out))

With Pint 0.8.1, I get [2. 4. 6.] as the output of this script, when I would expect either [1001. 1002. 1003.], [1.001 1.002 1.003] or similar with units attached. Pint returns the correct answer when out is not specified.

@hgrecco
Copy link
Owner

hgrecco commented May 29, 2018

Can you check without the out keyword?

@ngoldbaum
Copy link
Author

This script:

import numpy as np
from pint import UnitRegistry

u = UnitRegistry()

a = [1, 2, 3]*u.g
b = [1, 2, 3]*u.kg

print(np.add(a, b))

prints [1001. 2002. 3003.] gram, so indeed it has to do with using out.

@hgrecco
Copy link
Owner

hgrecco commented May 29, 2018

I wonder if when #630 is merged, this issue will be fixed.

@ngoldbaum
Copy link
Author

I get the same wrong answer with numpy 1.12.1 installed.

@jthielen
Copy link
Contributor

Just to note it down so it doesn't get forgotten, this issue (along with most other issues with optional arguments in NumPy ufuncs) remains after the refactor in #905.

@hgrecco hgrecco added the numpy Numpy related bug/enhancement label Dec 11, 2019
@hgrecco
Copy link
Owner

hgrecco commented May 26, 2021

This works in
Numpy: 1.20.1
Pint: 0.17

@hgrecco hgrecco closed this as completed May 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
numpy Numpy related bug/enhancement
Projects
None yet
Development

No branches or pull requests

3 participants