Thanks to visit codestin.com
Credit goes to github.com

Skip to content

FIX: Handle uint8 indices properly for colormap lookups #24970

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

Merged
merged 1 commit into from
Jan 14, 2023

Conversation

greglucas
Copy link
Contributor

PR Summary

Since we use subtraction to compute the lookup table indices we need to cast uints in addition to floats, so we can move the cast outside of the float block.

closes #24865

PR Checklist

Documentation and Tests

  • Has pytest style unit tests (and pytest passes)
  • [N/A] Documentation is sphinx and numpydoc compliant (the docs should build without error).
  • [N/A] New plotting related features are documented with examples.

Release Notes

  • [N/A] New features are marked with a .. versionadded:: directive in the docstring and documented in doc/users/next_whats_new/
  • [N/A] API changes are marked with a .. versionchanged:: directive in the docstring and documented in doc/api/next_api_changes/
  • [N/A] Release notes conform with instructions in next_whats_new/README.rst or next_api_changes/README.rst

xa[xa == self.N] = self.N - 1
# Avoid converting large positive values to negative integers.
np.clip(xa, -1, self.N, out=xa)
with np.errstate(invalid="ignore"):
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the errstate even still needed? AFAICT casting nan to int doesn't trigger an "invalid" error.

Copy link
Contributor Author

@greglucas greglucas Jan 13, 2023

Choose a reason for hiding this comment

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

I get one with it and get lots of failures in the pytest suite without ignoring.

python -c "import numpy; numpy.array([numpy.nan]).astype(int)"
<string>:1: RuntimeWarning: invalid value encountered in cast

@QuLogic QuLogic merged commit 99d39bd into matplotlib:main Jan 14, 2023
meeseeksmachine pushed a commit to meeseeksmachine/matplotlib that referenced this pull request Jan 14, 2023
rcomer added a commit that referenced this pull request Jan 14, 2023
…970-on-v3.7.x

Backport PR #24970 on branch v3.7.x (FIX: Handle uint8 indices properly for colormap lookups)
@greglucas greglucas deleted the cmap-cast branch January 31, 2023 17:32
@ksunden ksunden mentioned this pull request Feb 20, 2023
6 tasks
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]: NumPy 1.24 deprecation warnings
4 participants