1010from pygmt ._typing import PathLike
1111from pygmt .alias import Alias , AliasSystem
1212from pygmt .clib import Session
13- from pygmt .exceptions import GMTInvalidInput , GMTParameterError
13+ from pygmt .exceptions import GMTParameterError
1414from pygmt .helpers import build_arg_list , deprecate_parameter , fmt_docstring , use_alias
1515
1616__doctest_skip__ = ["grdfill" ]
@@ -31,41 +31,31 @@ def _validate_params(
3131 >>> _validate_params(constant_fill=20.0, grid_fill="bggrid.nc")
3232 Traceback (most recent call last):
3333 ...
34- pygmt.exceptions.GMTInvalidInput: Parameters ... are mutually exclusive .
34+ pygmt.exceptions.GMTParameterError: Mutually exclusive parameters: .. .
3535 >>> _validate_params(constant_fill=20.0, inquire=True)
3636 Traceback (most recent call last):
3737 ...
38- pygmt.exceptions.GMTInvalidInput: Parameters ... are mutually exclusive .
38+ pygmt.exceptions.GMTParameterError: Mutually exclusive parameters: .. .
3939 >>> _validate_params()
4040 Traceback (most recent call last):
4141 ...
4242 pygmt.exceptions.GMTParameterError: Missing parameter: requires at least one ...
4343 """
44- _fill_params = "'constant_fill'/'grid_fill'/'neighbor_fill'/'spline_fill'"
45-
46- n_given = sum (
47- param is not None and param is not False
48- for param in [
49- constant_fill ,
50- grid_fill ,
51- neighbor_fill ,
52- spline_fill ,
53- inquire ,
54- ]
55- )
56- if n_given > 1 : # More than one mutually exclusive parameter is given.
57- msg = f"Parameters { _fill_params } /'inquire' are mutually exclusive."
58- raise GMTInvalidInput (msg )
59- if n_given == 0 : # No parameters are given.
60- raise GMTParameterError (
61- at_least_one = {
62- "constant_fill" ,
63- "grid_fill" ,
64- "neighbor_fill" ,
65- "spline_fill" ,
66- "inquire" ,
67- }
68- )
44+ params = {
45+ "constant_fill" : constant_fill ,
46+ "grid_fill" : grid_fill ,
47+ "neighbor_fill" : neighbor_fill ,
48+ "spline_fill" : spline_fill ,
49+ "inquire" : inquire ,
50+ }
51+ n_given = sum (param is not None and param is not False for param in params .values ())
52+ match n_given :
53+ case 0 :
54+ raise GMTParameterError (at_least_one = params )
55+ case 1 :
56+ pass
57+ case _:
58+ raise GMTParameterError (at_most_one = params )
6959
7060
7161@fmt_docstring
0 commit comments