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.
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.
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.
(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.
Pytest does treat warnings as errors.
There was a problem hiding this comment.
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
imshowing 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 onmasterfails with:Details
And on latest
NumPyit also emits a warning later having to do withnp.clipnot likingnp.nanvalues.Alternatively,
imshowwith 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.maskedon line 409) so I didn't implement it here.PR Checklist
pytestpasses).flake8on changed files to check).flake8-docstringsandpydocstyle<4and 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).