Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ This project adheres to [Semantic Versioning](http://semver.org/).

## Unreleased

### Fixed
- Fix `px.imshow` not recognising `int32`/`uint32` images as integer data on Windows with NumPy 2, which made `contrast_rescaling="infer"` use a value-based range (e.g. 255) instead of the dtype range [[#5917](https://github.com/plotly/plotly.py/pull/5917)]


## [7.2.0] - 2026-11-24

Expand Down
19 changes: 7 additions & 12 deletions plotly/express/imshow_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,13 @@

from warnings import warn

_integer_types = (
np.byte,
np.ubyte, # 8 bits
np.short,
np.ushort, # 16 bits
np.intc,
np.uintc, # 16 or 32 or 64 bits
np.int_,
np.uint, # 32 or 64 bits
np.longlong,
np.ulonglong,
) # 64 bits
# Build the integer scalar types from their dtype characters rather than
# from named aliases: on Windows with NumPy 2, int32/uint32 arrays have
# ``np.long``/``np.ulong`` as their scalar type, which is distinct from
# ``np.intc``/``np.uintc`` and is not covered by ``np.int_`` (int64 there).
_integer_types = tuple(
dict.fromkeys(np.dtype(char).type for char in "bBhHiIlLqQ")
) # 8, 16, 32 and 64 bits, signed and unsigned
_integer_ranges = {t: (np.iinfo(t).min, np.iinfo(t).max) for t in _integer_types}
dtype_range = {
np.bool_: (False, True),
Expand Down
12 changes: 12 additions & 0 deletions tests/test_optional/test_px/test_imshow.py
Original file line number Diff line number Diff line change
Expand Up @@ -553,3 +553,15 @@ def test_imshow_xarray_facet_row_and_col():
annotations = [a.text for a in fig.layout.annotations]
assert any("row_dim=R1" in a for a in annotations)
assert any("col_dim=C1" in a for a in annotations)


# uint8 ("B") is left out: with contrast_rescaling="infer" it keeps zmax=None.
@pytest.mark.parametrize("dtype_char", list("bhHiIlLqQ"))
def test_imshow_infer_zmax_all_integer_dtypes(dtype_char):
# Every NumPy integer dtype must be recognised as an integer type, including
# int32/uint32 on Windows with NumPy 2, where their scalar type is
# np.long/np.ulong rather than np.intc/np.uintc.
dtype = np.dtype(dtype_char)
img = np.arange(100, dtype=dtype).reshape((10, 10))
fig = px.imshow(img, contrast_rescaling="infer")
assert fig.layout.coloraxis.cmax == np.iinfo(dtype).max