Repository navigation
Fix px.imshow integer dtype detection for int32/uint32 on Windows - #5917
Open
AsadullahMaliyawala wants to merge 2 commits into
Open
AsadullahMaliyawala wants to merge 2 commits into
AsadullahMaliyawala wants to merge 2 commits into
Conversation
With NumPy 2 on Windows, int32 and uint32 arrays have np.long/np.ulong as their scalar type, which is not one of the named aliases listed in _integer_types (np.intc/np.uintc are distinct types there and np.int_ is int64). px.imshow then treated such images as float data, so contrast_rescaling="infer" picked a value-based zmax (e.g. 255) instead of the dtype maximum. Build the type table from the dtype characters so every platform integer type is covered. Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: Claude <noreply@anthropic.com>
This branch has not been deployed
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.
Link to issue
No existing issue; found by running the test suite on Windows (details below).
Description of change
On Windows with NumPy 2,
int32/uint32arrays havenp.long/np.ulongas their scalar type. Those are separate types fromnp.intc/np.uintc, andnp.int_is int64 there, so neither is in_integer_typesinplotly/express/imshow_utils.py. As a resultpx.imshowtreatsint32/uint32images as float data andcontrast_rescaling="infer"picks a value-based range instead of the dtype range:The same mismatch applies to
rescale_intensity(..., in_range="dtype"), which looks types up in the same table.The fix builds
_integer_typesfrom the dtype characters"bBhHiIlLqQ", so every integer scalar type NumPy can produce on the current platform is covered (duplicates are dropped, so Linux/macOS get the same set as before).Testing strategy
test_imshow_source_dtype_zmax[infer-int32]fails on Windows before this change and passes after. CI runs on Linux only, which is why it was not caught.test_imshow_infer_zmax_all_integer_dtypes, which checkscmaxequals the dtype maximum for every integer dtype character (uint8 is left out becauseinferkeepszmax=Nonefor it). On Windows, thel/Lcases fail before the fix and pass after; on Linux all cases pass both ways.pytest tests/test_optional/test_px/test_imshow.py: 99 passed on Windows 11, Python 3.12, NumPy 2.5.5.ruff format --checkandruff checkare clean.Additional information (optional)
I used Claude Code (Claude Opus 5.5) to help find and fix this. I reproduced the bug and checked the change myself.
Guidelines