Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
QuLogic merged 1 commit intomatplotlib:masterfromlarsoner:masked
Sep 17, 2020
Merged

Conversation

larsoner
Copy link
Contributor

PR Summary

Deal withimshowing 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:

lib/matplotlib/image.py:639: in draw    im, l, b, trans = self.make_image(lib/matplotlib/image.py:924: in make_image    return self._make_image(self._A, bbox, transformed_bbox, clip,lib/matplotlib/image.py:476: in _make_image    vrange = np.array([vmin, vmax], dtype=scaled_dtype)_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = masked    def __float__(self):        """        Convert to float.            """        if self.size > 1:            raise TypeError("Only length-1 arrays can be converted "                            "to Python scalars")        elif self._mask:>           warnings.warn("Warning: converting a masked element to nan.", stacklevel=2)E           UserWarning: Warning: converting a masked element to nan.

And on latestNumPy 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

  • Has pytest style unit tests (andpytest passes).
  • IsFlake 8 compliant (runflake8 on changed files to check).
  • New features are documented, with examples if plot related.
  • Documentation is sphinx and numpydoc compliant (the docs shouldbuild without error).
  • Conforms to Matplotlib style conventions (installflake8-docstrings andpydocstyle<4 and runflake8 --docstring-convention=all).
  • New features have an entry indoc/users/next_whats_new/ (follow instructions in README.rst there).
  • API changes documented indoc/api/next_api_changes/ (follow instructions in README.rst there).

@tacaswelltacaswell added this to thev3.3.3 milestoneSep 16, 2020
@QuLogicQuLogic merged commita4128a7 intomatplotlib:masterSep 17, 2020
meeseeksmachine pushed a commit to meeseeksmachine/matplotlib that referenced this pull requestSep 17, 2020
@larsonerlarsoner deleted the masked branchSeptember 17, 2020 01:10
@larsoner
Copy link
ContributorAuthor

Thanks for the quick reviews!

QuLogic added a commit that referenced this pull requestSep 17, 2020
…500-on-v3.3.xBackport 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
Copy link
Contributor

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...

Copy link
ContributorAuthor

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 awith pytest.warns(None) as w: ... assert len(w) == 0 if it'll help

Copy link
ContributorAuthor

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 onmaster without the fixing-changes)

Copy link
Member

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.

Copy link
Contributor

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 inconftest.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.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@dopplershiftdopplershiftdopplershift left review comments

@QuLogicQuLogicQuLogic approved these changes

@tacaswelltacaswelltacaswell approved these changes

Assignees
No one assigned
Projects
None yet
Milestone
v3.3.3
Development

Successfully merging this pull request may close these issues.

4 participants
@larsoner@tacaswell@dopplershift@QuLogic

[8]ページ先頭

©2009-2025 Movatter.jp