diff --git a/pygmt/clib/session.py b/pygmt/clib/session.py index 9a4564d6771..d7c3301af62 100644 --- a/pygmt/clib/session.py +++ b/pygmt/clib/session.py @@ -1895,13 +1895,15 @@ def virtualfile_in( # noqa: PLR0912 _data = data match kind: case "image" if data.dtype != "uint8": - msg = ( - f"Input image has dtype: {data.dtype} which is unsupported, and " - "may result in an incorrect output. Please recast image to a uint8 " - "dtype and/or scale to 0-255 range, e.g. using a histogram " - "equalization function like skimage.exposure.equalize_hist." + raise GMTTypeError( + data.dtype, + reason=( + "Only uint8 images are supported. Please recast image to a " + "uint8 dtype and/or scale to 0-255 range, e.g. using a " + "histogram equalization function like " + "skimage.exposure.equalize_hist." + ), ) - warnings.warn(message=msg, category=RuntimeWarning, stacklevel=2) case "empty": # data is None, so data must be given via x/y/z. _data = [x, y] if z is not None: diff --git a/pygmt/tests/test_grdimage_image.py b/pygmt/tests/test_grdimage_image.py index 392dad9941b..a35858b126d 100644 --- a/pygmt/tests/test_grdimage_image.py +++ b/pygmt/tests/test_grdimage_image.py @@ -7,6 +7,7 @@ from pygmt import Figure from pygmt.clib.session import DTYPES_NUMERIC from pygmt.datasets import load_blue_marble +from pygmt.exceptions import GMTTypeError rioxarray = pytest.importorskip("rioxarray") @@ -53,6 +54,5 @@ def test_grdimage_image_dataarray_unsupported_dtype(dtype, xr_image): """ fig = Figure() image = xr_image.copy().astype(dtype=dtype) - with pytest.warns(expected_warning=RuntimeWarning) as record: + with pytest.raises(GMTTypeError, match="Only uint8 images are supported"): fig.grdimage(grid=image) - assert len(record) == 1