-
-
Notifications
You must be signed in to change notification settings - Fork 10.8k
BUG: Masked scalar comparison returns float #4332
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
Apparently the problem is with this logic if result.shape == () and m:
return masked in >>> numpy.ma.masked.dtype
dtype('float64') So the issue is not limited to comparison operators: >>> -numpy.ma.array(5, mask=True) is numpy.ma.masked
True |
Removed logic replacing masked scalar results from ufuncs with ma.masked singleton which has dtype float64. Fixes numpy#4332.
The whole idea is indeed to return a specific value, the masked singleton, however it is defined. That way, one can test whether an item of a The reason why it worked with |
No,
but
|
Would it be less radical if we preserve the existing behavior when result dtype is float, but return the correct type otherwise? |
@abalkin Can you give an example of what you have in mind? |
--- a/numpy/ma/core.py
+++ b/numpy/ma/core.py
@@ -2841,7 +2841,7 @@ class MaskedArray(ndarray):
# Don't modify inplace, we risk back-propagation
m = (m | d)
# Make sure the mask has the proper size
- if result.shape == () and m:
+ if result.shape == () and m and m.dtype == masked.dtype:
return masked
else:
result._mask = m I am not sure backward compatibility is such a big concern here. I understand that some people like In the long run, I would really like to see masked singleton use deprecated. As numpy type system getting reacher, it will cause more and more problems. |
Labelling a bug until the conversation concludes. |
Returning the |
Do you recall the reason for changing ma.masked dtype from int32 to float between oldnumeric.ma and numpy.ma? |
Moreover, the result has float dtype even if the masked scalar is an int:
The problem is not present in
oldnumeric
:The text was updated successfully, but these errors were encountered: