-
-
Notifications
You must be signed in to change notification settings - Fork 10.9k
ENH: Masked array __array_function__
could "fix" e.g. np.append
MA usage
#22338
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
Comments
This is a general issue of masked array (currently/always). The only solution would be to implement Implementing I am not seeing an issue, so will rename this one. I am not sure how easy/doable it is, but implementing an `array_function which normally just falls back to the builtin NumPy version may well be a good solution. Note that masked arrays severely lack any manpower to actually work on such changes. |
__array_function__
could "fix" e.g. np.append
MA usage
It wouldn't be hard to slightly modify np.append and have it call np.ma.append if the input is masked, but I'm not sure if that's really necessary here, since we already have a function for appending masked arrays. A better option might be to add a warning about using np.append on masked arrays in the documentation. |
It will be an uphill battle to convince anyone to add special paths for MA, which is why I am mentioning Adding a note/warning about this to the masked array documentation seems like a good plan though, I could not find one after a brief search, so it is likely missing. |
Hi Sebastian,
Yes, I’ve read a little about the woes of np.ma and how some coders avoid it altogether because of them, but I’m afraid I’m too invested in it to pull out now! As I said it’s no longer an issue for me (until the next time I carelessly use an np function when I should be using the np.ma function). If a comprehensive rewrite isn’t on the cards for the foreseeable future, it sounds like forwarding to known masked versions would be a good solution, transparent to users and without breaking code.
Cheers, Peter
<snip email stuff>
|
Describe the issue:
if I append a masked array and something else using np.append, it returns a masked array but with the original mask replaced with False. I wouldn't mind if it returned a non-masked array (my fault!), but the current behaviour seems positively misleading! If it returns a masked array, it should surely preserve the mask.
Reproduce the code example:
Error message:
No response
NumPy/Python version information:
1.20.3
Context for the issue:
No longer important for me (I corrected to np.ma.append), but could be misleading for others.
The text was updated successfully, but these errors were encountered: