8000 BUG operations involving MaskedArray with output given do not return output by mhvk · Pull Request #8416 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

Conversation

@mhvk
Copy link
Contributor
@mhvk mhvk commented Jan 22, 2017

EDIT -- turned into a PR.

Fixes an inconsistency found in #8414:

import numpy as np
a = np.ma.MaskedArray([1., 2.])
b = np.ma.MaskedArray(1.)
c = a.sum(out=b)
c is b
# True
d = np.true_divide(c, 2., out=b)
d is b
# False

Here, d is b should be True. That it is Falses suggested __array_wrap__ is not implemented quite correctly, probably missing a special path for if self is obj -- this PR fixes that.

@mhvk
Copy link
Contributor Author
mhvk commented Jan 22, 2017

I turned this into a PR to fix the issue that ufunc(ma, out=ma) would not return ma. cc @juliantaylor and @charris who noticed this in #8414.

numpy/ma/core.py Outdated
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: probably this is better done in __array_prepare__, but given that we hopefully soon have __array_func__ to work with, I felt it not quite worth it to try to define that...

numpy/ma/core.py Outdated
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just spent a little bit of effort trying to figure out if this copy had any purpose, but I can't see any. It's not related to the copying of masks discussed in #5580, for example.

Want to just remove it?

Without this commit, after an operation like
```
a = np.ma.MaskedArray([1., 2., 3.])
b = np.add(a, 1., out=a)
```
one would have `b is not a`.  With this PR, it is guaranteed that
`b is a`.
@mhvk mhvk force-pushed the ma/ensure-given-output-is-returned branch from 6640387 to 7927b3c Compare February 1, 2017 19:39
@mhvk
Copy link
Contributor Author
mhvk commented Feb 1, 2017

@ahaldane - OK, I agree it made little sence so just removed the strange copy (and rebased). Hopefully, tests will still pass.

@ahaldane
Copy link
Member
ahaldane commented Feb 1, 2017

Looks good to me otherwise, merging. Thanks @mhvk

@ahaldane ahaldane merged commit a12a171 into numpy:master Feb 1, 2017
@mhvk mhvk deleted the ma/ensure-given-output-is-returned branch February 1, 2017 21:36
juliantaylor added a commit to juliantaylor/numpy that referenced this pull request Feb 6, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

0