-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
BUG: Fix all-masked imshow #18500
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
BUG: Fix all-masked imshow #18500
Conversation
Thanks for the quick reviews! |
…500-on-v3.3.x Backport PR #18500 on branch v3.3.x (BUG: Fix all-masked imshow)
data = np.full((2, 2), np.nan) | ||
fig, ax = plt.subplots() | ||
ax.imshow(data) | ||
fig.canvas.draw_idle() # would emit a warning |
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.
Unless we run with warnings as error (which I'm pretty sure we don't) this test doesn't actually check that we don't issue warnings...
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.
I think it failed on master before the other changes in this PR, and this suggested to me that you do:
https://github.com/matplotlib/matplotlib/blob/master/lib/matplotlib/testing/conftest.py#L20
But I can wrap this in a with pytest.warns(None) as w: ... assert len(w) == 0
if it'll help
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.
(see the traceback in the description, that was from the original test on master
without the fixing-changes)
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.
Pytest does treat warnings as errors.
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.
Ah, I wasn't aware we had that turned on in conftest.py
. I'm used to testing on MetPy where so many upstream dependencies have warnings at times that running with warnings is impractical. Apologies for the noise.
PR Summary
Deal with
imshow
ing an array that is completely masked without emitting a warning. The added test/code emits 3 warnings onmaster
, none of which are particularly informative. The test onmaster
fails with:And on latest
NumPy
it also emits a warning later having to do withnp.clip
not likingnp.nan
values.Alternatively,
imshow
with all data masked could emit a warning, but it seems like the existing code had a chance to do that but didn't (there is an existingif a_min is np.ma.masked
on line 409) so I didn't implement it here.PR Checklist
pytest
passes).flake8
on changed files to check).flake8-docstrings
andpydocstyle<4
and runflake8 --docstring-convention=all
).doc/users/next_whats_new/
(follow instructions in README.rst there).doc/api/next_api_changes/
(follow instructions in README.rst there).