diff --git a/lib/matplotlib/tests/test_image.py b/lib/matplotlib/tests/test_image.py index 599265a2d4d8..8d7970078efa 100644 --- a/lib/matplotlib/tests/test_image.py +++ b/lib/matplotlib/tests/test_image.py @@ -1576,3 +1576,20 @@ def test_non_transdata_image_does_not_touch_aspect(): assert ax.get_aspect() == 1 ax.imshow(im, transform=ax.transAxes, aspect=2) assert ax.get_aspect() == 2 + + +@pytest.mark.parametrize( + 'dtype', + ('float64', 'float32', 'int16', 'uint16', 'int8', 'uint8'), +) +@pytest.mark.parametrize('ndim', (2, 3)) +def test_resample_dtypes(dtype, ndim): + # Issue 28448, incorrect dtype comparisons in C++ image_resample can raise + # ValueError: arrays must be of dtype byte, short, float32 or float64 + rng = np.random.default_rng(4181) + shape = (2, 2) if ndim == 2 else (2, 2, 3) + data = rng.uniform(size=shape).astype(np.dtype(dtype, copy=True)) + fig, ax = plt.subplots() + axes_image = ax.imshow(data) + # Before fix the following raises ValueError for some dtypes. + axes_image.make_image(None)[0] diff --git a/src/_image_wrapper.cpp b/src/_image_wrapper.cpp index 65c8c8324ebc..856dcf4ea3ce 100644 --- a/src/_image_wrapper.cpp +++ b/src/_image_wrapper.cpp @@ -173,20 +173,20 @@ image_resample(py::array input_array, if (auto resampler = (ndim == 2) ? ( - (dtype.is(py::dtype::of())) ? resample : - (dtype.is(py::dtype::of())) ? resample : - (dtype.is(py::dtype::of())) ? resample : - (dtype.is(py::dtype::of())) ? resample : - (dtype.is(py::dtype::of())) ? resample : - (dtype.is(py::dtype::of())) ? resample : + (dtype.equal(py::dtype::of())) ? resample : + (dtype.equal(py::dtype::of())) ? resample : + (dtype.equal(py::dtype::of())) ? resample : + (dtype.equal(py::dtype::of())) ? resample : + (dtype.equal(py::dtype::of())) ? resample : + (dtype.equal(py::dtype::of())) ? resample : nullptr) : ( // ndim == 3 - (dtype.is(py::dtype::of())) ? resample : - (dtype.is(py::dtype::of())) ? resample : - (dtype.is(py::dtype::of())) ? resample : - (dtype.is(py::dtype::of())) ? resample : - (dtype.is(py::dtype::of())) ? resample : - (dtype.is(py::dtype::of())) ? resample : + (dtype.equal(py::dtype::of())) ? resample : + (dtype.equal(py::dtype::of())) ? resample : + (dtype.equal(py::dtype::of())) ? resample : + (dtype.equal(py::dtype::of())) ? resample : + (dtype.equal(py::dtype::of())) ? resample : + (dtype.equal(py::dtype::of())) ? resample : nullptr)) { Py_BEGIN_ALLOW_THREADS resampler( pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy