Skip to content

Commit 6eea101

Browse files
authored
[BREAKING] Raise GMTTypeError exception for unsupported image dtypes (#4673)
1 parent b1b00a5 commit 6eea101

2 files changed

Lines changed: 10 additions & 8 deletions

File tree

pygmt/clib/session.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1895,13 +1895,15 @@ def virtualfile_in( # noqa: PLR0912
18951895
_data = data
18961896
match kind:
18971897
case "image" if data.dtype != "uint8":
1898-
msg = (
1899-
f"Input image has dtype: {data.dtype} which is unsupported, and "
1900-
"may result in an incorrect output. Please recast image to a uint8 "
1901-
"dtype and/or scale to 0-255 range, e.g. using a histogram "
1902-
"equalization function like skimage.exposure.equalize_hist."
1898+
raise GMTTypeError(
1899+
data.dtype,
1900+
reason=(
1901+
"Only uint8 images are supported. Please recast image to a "
1902+
"uint8 dtype and/or scale to 0-255 range, e.g. using a "
1903+
"histogram equalization function like "
1904+
"skimage.exposure.equalize_hist."
1905+
),
19031906
)
1904-
warnings.warn(message=msg, category=RuntimeWarning, stacklevel=2)
19051907
case "empty": # data is None, so data must be given via x/y/z.
19061908
_data = [x, y]
19071909
if z is not None:

pygmt/tests/test_grdimage_image.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from pygmt import Figure
88
from pygmt.clib.session import DTYPES_NUMERIC
99
from pygmt.datasets import load_blue_marble
10+
from pygmt.exceptions import GMTTypeError
1011

1112
rioxarray = pytest.importorskip("rioxarray")
1213

@@ -53,6 +54,5 @@ def test_grdimage_image_dataarray_unsupported_dtype(dtype, xr_image):
5354
"""
5455
fig = Figure()
5556
image = xr_image.copy().astype(dtype=dtype)
56-
with pytest.warns(expected_warning=RuntimeWarning) as record:
57+
with pytest.raises(GMTTypeError, match="Only uint8 images are supported"):
5758
fig.grdimage(grid=image)
58-
assert len(record) == 1

0 commit comments

Comments
 (0)