From 8c158dee3e8f16d077ed730e09addca8e5f6b00a Mon Sep 17 00:00:00 2001 From: Youssef Elaasri Date: Thu, 19 Nov 2026 17:43:46 +0100 Subject: [PATCH 1/2] Replace np.float_ with np.float64 in imshow_utils for NumPy 2 np.float_ was removed in NumPy 2.0, so rescale_intensity(img, out_range=(a, b)) raised AttributeError. --- CHANGELOG.md | 1 + plotly/express/imshow_utils.py | 2 +- tests/test_optional/test_px/test_imshow.py | 8 ++++++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8cc2568a0b5..c10d7d17e4d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ This project adheres to [Semantic Versioning](http://semver.org/). - Remove Python 3.8 and Python 3.9 support. plotly.py now requires Python 3.10 or later. [[#5883](https://github.com/plotly/plotly.py/pull/5883)] ### Fixed +- Fix `rescale_intensity` in `plotly.express.imshow_utils` raising `AttributeError` under NumPy 2 when `out_range` is a `(min, max)` pair, by replacing the removed `np.float_` alias with `np.float64` [[#PR](https://github.com/plotly/plotly.py/pull/PR)] - Fix figures in JupyterLab not redrawing when their output is updated with `update_display_data` (for example `DisplayHandle.update`), which also kept animations in other kernels on their first frame [[#5865](https://github.com/plotly/plotly.py/pull/5865)], with thanks to @AllenDowney for the contribution! - Fix `mpl_to_plotly` tick marker mirroring, axis positioning, and trace visibility for twinned and overlaid subplots (such as `twinx` and `twiny`) [[#5310](https://github.com/plotly/plotly.py/pull/5310)], with thanks to @robertoffmoura for the contribution! - Fix `mpl_to_plotly` losing matplotlib axis line colors by exporting the color of each axis's displayed spine to the plotly x and y axis `linecolor` [[#5311](https://github.com/plotly/plotly.py/pull/5311)], with thanks to @robertoffmoura for the contribution! diff --git a/plotly/express/imshow_utils.py b/plotly/express/imshow_utils.py index 7f110ede4d0..85456ca39a0 100644 --- a/plotly/express/imshow_utils.py +++ b/plotly/express/imshow_utils.py @@ -109,7 +109,7 @@ def _output_dtype(dtype_or_range): """ if type(dtype_or_range) in [list, tuple, np.ndarray]: # pair of values: always return float. - return np.float_ + return np.float64 if isinstance(dtype_or_range, type): # already a type: return it return dtype_or_range diff --git a/tests/test_optional/test_px/test_imshow.py b/tests/test_optional/test_px/test_imshow.py index 3a0e230eb9c..d49bdc3133b 100644 --- a/tests/test_optional/test_px/test_imshow.py +++ b/tests/test_optional/test_px/test_imshow.py @@ -553,3 +553,11 @@ 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) + + +def test_rescale_intensity_out_range_pair(): + # A (min, max) out_range used np.float_, which NumPy 2 removed + img = np.arange(100, dtype=np.uint8).reshape((10, 10)) + out = rescale_intensity(img, out_range=(0, 1)) + assert out.dtype == np.float64 + assert out.min() == 0 and out.max() == 1 From aab6bd2641f0cfd77d87800e3fcd0b03b36dcb22 Mon Sep 17 00:00:00 2001 From: Youssef Elaasri Date: Thu, 19 Nov 2026 17:50:15 +0100 Subject: [PATCH 2/2] Add PR number to changelog entry --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c10d7d17e4d..a3e29c9a7de 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,7 +11,7 @@ This project adheres to [Semantic Versioning](http://semver.org/). - Remove Python 3.8 and Python 3.9 support. plotly.py now requires Python 3.10 or later. [[#5883](https://github.com/plotly/plotly.py/pull/5883)] ### Fixed -- Fix `rescale_intensity` in `plotly.express.imshow_utils` raising `AttributeError` under NumPy 2 when `out_range` is a `(min, max)` pair, by replacing the removed `np.float_` alias with `np.float64` [[#PR](https://github.com/plotly/plotly.py/pull/PR)] +- Fix `rescale_intensity` in `plotly.express.imshow_utils` raising `AttributeError` under NumPy 2 when `out_range` is a `(min, max)` pair, by replacing the removed `np.float_` alias with `np.float64` [[#5890](https://github.com/plotly/plotly.py/pull/5890)], with thanks to @youssef-elaasri for the contribution! - Fix figures in JupyterLab not redrawing when their output is updated with `update_display_data` (for example `DisplayHandle.update`), which also kept animations in other kernels on their first frame [[#5865](https://github.com/plotly/plotly.py/pull/5865)], with thanks to @AllenDowney for the contribution! - Fix `mpl_to_plotly` tick marker mirroring, axis positioning, and trace visibility for twinned and overlaid subplots (such as `twinx` and `twiny`) [[#5310](https://github.com/plotly/plotly.py/pull/5310)], with thanks to @robertoffmoura for the contribution! - Fix `mpl_to_plotly` losing matplotlib axis line colors by exporting the color of each axis's displayed spine to the plotly x and y axis `linecolor` [[#5311](https://github.com/plotly/plotly.py/pull/5311)], with thanks to @robertoffmoura for the contribution!