Skip to content

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

Merged
merged 4 commits into from
Aug 29, 2017

Conversation

dopplershift
Copy link
Contributor

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.

@dopplershift dopplershift added this to the 2.1 (next point release) milestone Aug 17, 2017
if hasattr(x, 'mask'):
return np.ma.asarray(x, float).filled(np.nan)
else:
return np.asarray(x, float)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is asanyarray better here?

Copy link
Contributor Author

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.

@tacaswell
Copy link
Member

Is there a way to test this without picking up a pint dependency?

@dopplershift
Copy link
Contributor Author

Looks like I already started a small pint knock-off in test_units.py. I'll add a test in there.

@dopplershift
Copy link
Contributor Author

Added a test. Also rolled back changes to collections.py; these were adding a conversion to array that isn't appropriate given that things like set_verts take lists of arrays--causing broken tests.

@dopplershift
Copy link
Contributor Author

IMO, this is good to go.

@dopplershift
Copy link
Contributor Author

I went ahead and added the test I developed for #8910. The only outstanding question on that is whether the call to autoscale_view() should really be necessary.

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.
@dopplershift
Copy link
Contributor Author

Went ahead and added a new callback for the 'units finalize' event that calls both relim and autoscale_view (was just relim before). Also rebased on lastest master and fixed a pep8 violation.

This adds a independent callback for units changes that both updates the
data limits (relim) as well as the view limits (autoscale_view).
@dopplershift
Copy link
Contributor Author

Fixed tests by making sure to only autoscale relevant axis.

@dopplershift dopplershift added the Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions. label Aug 23, 2017
@tacaswell
Copy link
Member

I suspect that this will make @TD22057 happy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions. topic: units and array ducktypes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants