-
-
Notifications
You must be signed in to change notification settings - Fork 10.8k
BUG: numpy.ma.min/max fails for uint and float16 dtypes #27584
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
base: main
Are you sure you want to change the base?
Conversation
@fengluoqiuwu I am not sure this is the right fix (changing the return type of
Thanks! |
Apologies for the confusion. I updated the fix with another way but forgot to change the description accordingly. I'll ensure the details match next time. I'll add the unit test now to cover the case solved by this PR. Thanks for the suggestion! |
I agree that using unsafe casting here is incorrect. |
Unsigned int works with the patch below, but |
Considering that masked arrays in NumPy use a mask to ignore certain values during calculations, do we really need to be concerned about the actual fill value within the array when the mask is applied, as properties It seems that I removed the code handling inf values, and the tests of ma still ran without issues. When using data type which maximum is smaller than the default value, and we can't fill the masked array with default value. For example, it can't fill with |
I agree with you. Using unsafe casting here doesn't seem right. It might trigger a runtime warning with |
As mentioned in the documentation, the masked array should be filled with the result of the specific function. Therefore, I would prefer not to include the inf check, as it could alter the fill value. I will open a new issue to discuss what value should be used when encountering |
The PR addresses the issue by using Currently:
I would expect |
I actually agree with this approach, as the original design causes many issues and bugs. I would prefer to take a more aggressive approach, which is to enforce that the fill value matches the dtype of the array. However, I think it would be better to address these issues along with other design problems in MaskedArray in the same version to avoid making multiple changes to its behavior. (The more aggressive approach would be to refactor the current MaskedArray implementation, as I’ve found that many bugs due to design flaws cannot be easily fixed.) |
Delete inf check.
Due to in the doc it says that we should use the output of
minimun_fill_value
, which isinf
as dytype is floatingpoint.Fixes #27580