Skip to content
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

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

Closed
wants to merge 1 commit into from

Conversation

tacaswell
Copy link
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 tacaswell added this to the v3.9.0 milestone Nov 10, 2023
oscargus
oscargus previously approved these changes Nov 10, 2023
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)
):
Copy link
Contributor

@anntzer anntzer Nov 10, 2023

Choose a reason for hiding this comment

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

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
Copy link
Member

rcomer commented Nov 10, 2023

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

@tacaswell
Copy link
Member Author

Closing in favor of #27301

@tacaswell tacaswell closed this Mar 6, 2024
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