Skip to content

Commit e436168

Browse files
authored
Figure.grdview: Raise GMTParameterError when parameter conflicts with specific surftype (#4397)
1 parent 00a5f02 commit e436168

2 files changed

Lines changed: 16 additions & 13 deletions

File tree

pygmt/src/grdview.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from pygmt._typing import PathLike
1111
from pygmt.alias import Alias, AliasSystem
1212
from pygmt.clib import Session, __gmt_version__
13-
from pygmt.exceptions import GMTInvalidInput, GMTParameterError
13+
from pygmt.exceptions import GMTParameterError
1414
from pygmt.helpers import build_arg_list, deprecate_parameter, fmt_docstring, use_alias
1515
from pygmt.src.grdinfo import grdinfo
1616

@@ -80,17 +80,20 @@ def _alias_option_Q( # noqa: N802
8080
)
8181

8282
if dpi is not None and surftype != "image":
83-
msg = "Parameter 'dpi' can only be used when 'surftype' is 'image'."
84-
raise GMTInvalidInput(msg)
83+
raise GMTParameterError(
84+
conflicts_with=("dpi", [f"surftype={surftype!r}"]),
85+
reason="'dpi' is allowed only when 'surftype' is 'image'.",
86+
)
8587
if nan_transparent and surftype != "image":
86-
msg = "Parameter 'nan_transparent' can only be used when 'surftype' is 'image'."
87-
raise GMTInvalidInput(msg)
88+
raise GMTParameterError(
89+
conflicts_with=("nan_transparent", [f"surftype={surftype!r}"]),
90+
reason="'nan_transparent' is allowed only when 'surftype' is 'image'.",
91+
)
8892
if mesh_fill is not None and surftype not in {"mesh", "waterfall_x", "waterfall_y"}:
89-
msg = (
90-
"Parameter 'mesh_fill' can only be used when 'surftype' is 'mesh', "
91-
"'waterfall_x', or 'waterfall_y'."
93+
raise GMTParameterError(
94+
conflicts_with=("mesh_fill", [f"surftype={surftype!r}"]),
95+
reason="'mesh_fill' is allowed only when 'surftype' is 'mesh', 'waterfall_x', or 'waterfall_y'.",
9296
)
93-
raise GMTInvalidInput(msg)
9497

9598
return [
9699
Alias(

pygmt/tests/test_grdview.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import pytest
66
from pygmt import Figure, grdcut
7-
from pygmt.exceptions import GMTInvalidInput, GMTParameterError, GMTTypeError
7+
from pygmt.exceptions import GMTParameterError, GMTTypeError
88
from pygmt.helpers import GMTTempFile
99
from pygmt.helpers.testing import load_static_earth_relief
1010

@@ -330,11 +330,11 @@ def test_grdview_invalid_surftype(gridfile):
330330
parameters.
331331
"""
332332
fig = Figure()
333-
with pytest.raises(GMTInvalidInput):
333+
with pytest.raises(GMTParameterError):
334334
fig.grdview(grid=gridfile, surftype="surface", dpi=300)
335-
with pytest.raises(GMTInvalidInput):
335+
with pytest.raises(GMTParameterError):
336336
fig.grdview(grid=gridfile, surftype="surface", nan_transparent=True)
337-
with pytest.raises(GMTInvalidInput):
337+
with pytest.raises(GMTParameterError):
338338
fig.grdview(grid=gridfile, surftype="surface", mesh_fill="red")
339339

340340

0 commit comments

Comments
 (0)