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

MaskedArray ufuncs don't return out parameter #7394

Open
ahaldane opened this issue Mar 8, 2016 · 1 comment
Open

MaskedArray ufuncs don't return out parameter #7394

ahaldane opened this issue Mar 8, 2016 · 1 comment
Labels
component: numpy.ma masked arrays

Comments

@ahaldane
Copy link
Member

ahaldane commented Mar 8, 2016

The ufuncs defined for MaskedArrays don't return out if it is supplied as a keyword, unlike normal ufuncs.

>>> a = np.ones(2)
>>> np.add([1,1], 2, out=a) is a
True
>>> np.ma.add([1,1], 2, out=a) is a
False
@mhvk
Copy link
Contributor

mhvk commented Mar 9, 2016

I don't think ma ufuncs do anything with out -- in your example, a contains a regular array, while the output is a masked array. Specifically,

ma = np.ma.add([1,1], 2, out=a)
ma.data.base is a
# True

Looking at the code, __array_wrap__ simply views the output of the ufunc (i.e., a) as a MaskedArray and then goes through its logic with the mask. To get this right, one would have to use __array_prepare__ to turn the output array into a masked version before filling it in the calculation.

@eric-wieser eric-wieser added the component: numpy.ma masked arrays label Feb 19, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: numpy.ma masked arrays
Projects
None yet
Development

No branches or pull requests

3 participants