-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
BUG: Fix weird behavior with mask and units (Fixes #8908) #9049
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
Conversation
if hasattr(x, 'mask'): | ||
return np.ma.asarray(x, float).filled(np.nan) | ||
else: | ||
return np.asarray(x, float) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is asanyarray
better here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The existing code was always going to a straight-up numpy array, and since that part of the behavior didn't seem to be causing any unit-related problems, it seemed best to be conservative and keep it as asarray
.
Is there a way to test this without picking up a pint dependency? |
Looks like I already started a small pint knock-off in |
Added a test. Also rolled back changes to |
IMO, this is good to go. |
I went ahead and added the test I developed for #8910. The only outstanding question on that is whether the call to |
Refactor many places that check for masked arrays, and fill the masked values with nans, with a helper to accomplish that. In the helper, replace the isinstance check with a attribute check for 'mask'. This allows libraries, like pint, that wrap mask arrays to pass the check and be converted appropriately. Also fix one spot using atleast_1d with _check_1d.
This tests that unit libraries that wrap arrays, like pint, work properly. This adds an image test that checks current behavior, which seems to be fully correct.
Went ahead and added a new callback for the |
This adds a independent callback for units changes that both updates the data limits (relim) as well as the view limits (autoscale_view).
Fixed tests by making sure to only autoscale relevant axis. |
I suspect that this will make @TD22057 happy. |
Refactor many places that check for masked arrays, and fill the masked
values with nans, with a helper to accomplish that. In the helper,
replace the isinstance check with a attribute check for 'mask'. This
allows libraries, like pint, that wrap mask arrays to pass the check and
be converted appropriately.
Also fix one spot using
atleast_1d
with_check_1d
.