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

Operating elementwise with numpy masked arrays #37

Closed
canesin opened this issue Jul 24, 2013 · 5 comments · Fixed by #963
Closed

Operating elementwise with numpy masked arrays #37

canesin opened this issue Jul 24, 2013 · 5 comments · Fixed by #963
Labels
bug enhancement numpy Numpy related bug/enhancement

Comments

@canesin
Copy link

canesin commented Jul 24, 2013

It is not working as suposed with masked arrays, it creats objects by elements.

https://gist.github.com/canesin/6072390

hgrecco added a commit that referenced this issue Jul 26, 2013
@hgrecco
Copy link
Owner

hgrecco commented Jul 26, 2013

The new test case shows that the bug is because MaskedArray (and not Quantity) is handling the multiplication. When the order of the operation is reversed, everything works as expected.

@canesin
Copy link
Author

canesin commented Jul 27, 2013

It looses the masked behaviour.

@hgrecco
Copy link
Owner

hgrecco commented Jul 27, 2013

Multiplying meter by a masked array works as expected:

>>> from pint import UnitRegistry
>>> ureg = UnitRegistry()
>>> import numpy as np
>>> x = np.ma.masked_array([1, 2, 3], mask=[True, True, False])
>>> q = ureg.meter * x
>>> q
<Quantity([-- -- 3], 'meter')>
>>> q.magnitude
masked_array(data = [-- -- 3],
             mask = [ True  True False],
       fill_value = 999999)

Is the converse that is not working properly:

>>> q = x * ureg.meter
>>> q
masked_array(data = [-- -- <Quantity(3, 'meter')>],
             mask = [ True  True False],
       fill_value = 999999)

Can you confirm this in your system?

The problem is that the multiplication is always handled by the left operand. I think that the bug is that the ufunc is not honoring of the array_priority value. I am trying to confirm this with the numpy people.

@canesin
Copy link
Author

canesin commented Jul 27, 2013

Yes, I can confirm that it works with multiplication by left. thanks.

@hgrecco
Copy link
Owner

hgrecco commented Dec 3, 2019

Review once that #905 is implemented

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug enhancement numpy Numpy related bug/enhancement
Projects
None yet
2 participants