diff --git a/CHANGELOG.md b/CHANGELOG.md index af8bac065a..e0a0a17d5c 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` raising `AttributeError` on NumPy 2 when `out_range` is a pair, by replacing the removed `np.float_` with `np.float64` [[#5893](https://github.com/plotly/plotly.py/issues/5893)] - 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 7f110ede4d..85456ca39a 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 3a0e230eb9..d7dbf576f3 100644 --- a/tests/test_optional/test_px/test_imshow.py +++ b/tests/test_optional/test_px/test_imshow.py @@ -364,6 +364,11 @@ def test_imshow_source_dtype_zmax(dtype, contrast_rescaling): < 1 ) +def test_rescale_intensity_out_range_pair(): + # Regression test for #5893: np.float_ was removed in NumPy 2.0 + out = rescale_intensity(np.arange(4, dtype=np.uint8), out_range=(0, 1)) + assert out.dtype == np.float64 + np.testing.assert_allclose(out, [0.0, 1 / 3, 2 / 3, 1.0]) @pytest.mark.parametrize("backend", ["auto", "pypng", "pil"]) def test_imshow_backend(backend):