BUG: Fix bugs for np.ma.count and copy on builtin types (issue #8019)#8060
BUG: Fix bugs for np.ma.count and copy on builtin types (issue #8019)#8060skwbc wants to merge 3 commits intonumpy:masterfrom skwbc:issue#8019
Conversation
|
I'm worried this goes a little too far. What about the case of a subclass of MaskedArray? In the old code the subclass's method would be called, but not anymore here. Actually, it seems to me that the |
|
@ahaldane I didn't care about subclasses of MaskedArray and I fixed the code using np.ma.asanyarray. It corresponds to np.asanyarray for MaskedArray (it conserves subclasses of MaskedArray). |
| method = getattr(MaskedArray, method_name, None) | ||
| if method is not None: | ||
| return method(MaskedArray(a), *args, **params) | ||
| return method(marr, *args, **params) |
There was a problem hiding this comment.
It might be nicer not to repeat this line, by flipping the if statement
| @@ -6390,18 +6390,14 @@ def __call__(self, a, *args, **params): | |||
| arr = args[0] | |||
| args[0] = a | |||
| a = arr | |||
There was a problem hiding this comment.
While we're here, can we change these lines to a, args[0] = args[0], a?
|
Otherwise generally looks good to me |
As explained in issue #8019
listhas acount(in Python3) and copy method, and_frommethod.__call__tries to call them instead ofnp.ma.MaskedArray.countandnp.ma.MaskedArray.copy.By using methods on MaskedArray always, we can resolve this issue (unexpected call of builtin object methods).
I think this fix is fine because docstring on _frommethod says “Define functions from existing MaskedArray methods”.