{{ message }}
Fix NoNorm cursor formatting for uint8 images#31967
Open
goutamadwant wants to merge 1 commit into
Open
Conversation
scottshambaugh
left a comment
Contributor
There was a problem hiding this comment.
Please use our PR template that auto-populates when you open a PR. Specifically, you are missing its AI Disclosure section.
|
|
||
|
|
||
| def test_format_cursor_data_uint8_no_norm(): | ||
| from matplotlib.backend_bases import MouseEvent |
Contributor
There was a problem hiding this comment.
Could you move this import (and the others in the surrounding functions) to the top of the file instead of in-line?
Contributor
There was a problem hiding this comment.
There are more of these in the file that can be cleaned up. Once that's done, this looks good to me
e4cb56a to
34c6aed
Compare
Author
rcomer
reviewed
Jul 2, 2026
Convert normalized scalar values to Python scalars before computing neighboring color intervals. This avoids NumPy scalar overflow when NoNorm returns a uint8 cursor value for image data. Add a regression test for cursor formatting on uint8 image data with NoNorm.
34c6aed to
657864d
Compare
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
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

PR summary
closes #31960
This fixes cursor formatting for
uint8image data displayed withcolors.NoNorm().NoNormreturns the original NumPy scalar value. With recent NumPy versions, multiplying auint8cursor value by the colormap size can raiseOverflowErrorwhile Matplotlib computes neighboring color intervals for cursor display precision.This change converts the normalized scalar to a Python scalar at the point where that interval arithmetic is needed, preserving the existing cursor readout behavior while avoiding the narrow-dtype overflow.
Before this change, formatting a
uint8cursor value from aNoNormimage raisedOverflowError. After this change, it returns the expected cursor label.Breaking changes: None.
Tests run:
python -P -m pytest lib/matplotlib/tests/test_image.py::test_format_cursor_data_uint8_no_norm lib/matplotlib/tests/test_image.py::test_format_cursor_datapython -P -m pytest lib/matplotlib/tests/test_image.py::test_format_cursor_data_multinorm lib/matplotlib/tests/test_artist.py::test_format_cursor_data_BoundaryNormpython -P -m pytest lib/matplotlib/tests/test_image.py -k cursor_dataAI Disclosure
I used Codex to review the relevant code and understand the existing codebase.
PR checklist