FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

FIX: also exclude np.nan in RGB(A) in color mapping by tacaswell · Pull Request #27303 · matplotlib/matplotlib · GitHub

Repository navigation

FIX: also exclude np.nan in RGB(A) in color mapping - #27303

Closed
tacaswell wants to merge 1 commit into
matplotlib:mainfrom
tacaswell:fix/RGBA_nan
Closed

tacaswell wants to merge 1 commit into
matplotlib:mainfrom
tacaswell:fix/RGBA_nan

Conversation

Copy link
Copy Markdown
Member

closes #27301

PR summary

The docstring says "values must be on [0, 1] gamut" as is our standard encoding for float RGB(A) arrays. We check that the min and max are not outside of this range, but due to the way comparisons work with np.nan our test erroneously passed.

This adds an explict check for np.nan

PR checklist

tacaswell added this to the v3.9.0 milestone Nov 10, 2023
oscargus previously approved these changes Nov 10, 2023
Comment thread lib/matplotlib/cm.py
if norm and (xx.max() > 1 or xx.min() < 0):
if norm and (
np.any(np.isnan(xx)) or (xx.max() > 1 or xx.min() < 0)
):

anntzer Nov 10, 2023 •
edited
Loading

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Rewrite as
if not (xx.min() >= 0 and xx.max() <= 1) (with a comment explaining that this form also excludes nans) and no extra nan checking to save a tiny bit of performance?

rcomer commented Nov 10, 2023

Copy link
Copy Markdown
Member

I checked out this branch and found it does not affect the examples in #27301. I think because norm is False.

Unless I've done something silly, which is always possible...

oscargus dismissed their stale review November 10, 2023 14:59

As there were doubts about how to handle it (and now if it actually works), it is probably better that I do not approve (only) based on seemingly sensible code.

Copy link
Copy Markdown
Member Author

Closing in favor of #27301

tacaswell closed this Mar 6, 2024
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: imshow allows RGB(A) images with np.nan values to pass

5 participants


Back | FazBrowse Home | New Git URL