From 8fe6a1328e380da6e4394f4d0e37a63c08eba81e Mon Sep 17 00:00:00 2001 From: chuan Date: Wed, 28 Jan 2026 17:46:02 +0800 Subject: [PATCH 01/26] Add GMTParameterError and deprecate GMTInvalidInput --- doc/api/index.rst | 1 + pygmt/exceptions.py | 48 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/doc/api/index.rst b/doc/api/index.rst index 7dd3d35afd3..73acdfb9039 100644 --- a/doc/api/index.rst +++ b/doc/api/index.rst @@ -294,6 +294,7 @@ All custom exceptions are derived from :class:`pygmt.exceptions.GMTError`. exceptions.GMTError exceptions.GMTInvalidInput + exceptions.GMTParameterError exceptions.GMTVersionError exceptions.GMTOSError exceptions.GMTCLibError diff --git a/pygmt/exceptions.py b/pygmt/exceptions.py index dedb64db7fa..a9d4c7f7f9a 100644 --- a/pygmt/exceptions.py +++ b/pygmt/exceptions.py @@ -41,7 +41,55 @@ class GMTCLibNoSessionError(GMTCLibError): class GMTInvalidInput(GMTError): # noqa: N818 """ Raised when the input of a function/method is invalid. + + .. deprecated:: 0.13.0 + Use :class:`GMTParameterError` instead. + """ + + +class GMTParameterError(GMTError): # noqa: N818 """ + Raised when parameters are missing or invalid. + + Parameters + ---------- + required + Names of required parameters. + require_any + Names of parameters where at least one must be specified. + exclusive + Names of mutually exclusive parameters. + reason + Detailed reason why the parameters are invalid. + """ + + def __init__( + self, + *, + required: set[str] | None = None, + require_any: set[str] | None = None, + exclusive: set[str] | None = None, + reason: str | None = None, + ): + msg = [] + if required: + msg.append( + "Required parameter(s) are missing: " + f"{', '.join(repr(par) for par in required)}." + ) + if require_any: + msg.append( + "At least one of the following parameters must be specified: " + f"{', '.join(repr(par) for par in require_any)}." + ) + if exclusive: + msg.append( + "Mutually exclusive parameter(s) are specified: " + f"{', '.join(repr(par) for par in exclusive)}." + ) + if reason: + msg.append(reason) + super().__init__(" ".join(msg)) class GMTVersionError(GMTError): From 737defa89624a82d2fba2cfbf7fcf7c9a8c9f350 Mon Sep 17 00:00:00 2001 From: chuan Date: Wed, 28 Jan 2026 17:49:57 +0800 Subject: [PATCH 02/26] fix format --- pygmt/exceptions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pygmt/exceptions.py b/pygmt/exceptions.py index a9d4c7f7f9a..2664d9cfb00 100644 --- a/pygmt/exceptions.py +++ b/pygmt/exceptions.py @@ -47,7 +47,7 @@ class GMTInvalidInput(GMTError): # noqa: N818 """ -class GMTParameterError(GMTError): # noqa: N818 +class GMTParameterError(GMTError): """ Raised when parameters are missing or invalid. From ae59d2fa98cf8328772f7696a14e6ee64324786d Mon Sep 17 00:00:00 2001 From: chuan Date: Wed, 28 Jan 2026 18:21:46 +0800 Subject: [PATCH 03/26] focus on required parameters --- pygmt/exceptions.py | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/pygmt/exceptions.py b/pygmt/exceptions.py index 2664d9cfb00..c47331e4b53 100644 --- a/pygmt/exceptions.py +++ b/pygmt/exceptions.py @@ -41,9 +41,6 @@ class GMTCLibNoSessionError(GMTCLibError): class GMTInvalidInput(GMTError): # noqa: N818 """ Raised when the input of a function/method is invalid. - - .. deprecated:: 0.13.0 - Use :class:`GMTParameterError` instead. """ @@ -67,8 +64,6 @@ def __init__( self, *, required: set[str] | None = None, - require_any: set[str] | None = None, - exclusive: set[str] | None = None, reason: str | None = None, ): msg = [] @@ -77,16 +72,6 @@ def __init__( "Required parameter(s) are missing: " f"{', '.join(repr(par) for par in required)}." ) - if require_any: - msg.append( - "At least one of the following parameters must be specified: " - f"{', '.join(repr(par) for par in require_any)}." - ) - if exclusive: - msg.append( - "Mutually exclusive parameter(s) are specified: " - f"{', '.join(repr(par) for par in exclusive)}." - ) if reason: msg.append(reason) super().__init__(" ".join(msg)) From 73b9c42674c9dab4b1ae4b145f117db454ecc994 Mon Sep 17 00:00:00 2001 From: Xingchen He Date: Wed, 28 Jan 2026 18:39:40 +0800 Subject: [PATCH 04/26] Update pygmt/exceptions.py Co-authored-by: Dongdong Tian --- pygmt/exceptions.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/pygmt/exceptions.py b/pygmt/exceptions.py index c47331e4b53..3a111e150df 100644 --- a/pygmt/exceptions.py +++ b/pygmt/exceptions.py @@ -52,10 +52,6 @@ class GMTParameterError(GMTError): ---------- required Names of required parameters. - require_any - Names of parameters where at least one must be specified. - exclusive - Names of mutually exclusive parameters. reason Detailed reason why the parameters are invalid. """ From 8a778e45600f227458e09c4154c53225c4ab00ba Mon Sep 17 00:00:00 2001 From: chuan Date: Wed, 28 Jan 2026 19:36:13 +0800 Subject: [PATCH 05/26] add support for single parameter: string input, list input, and tuple input update source files to support the new feature --- pygmt/exceptions.py | 60 ++++++++++++++++++---------------- pygmt/helpers/validators.py | 10 +++--- pygmt/params/box.py | 7 ++-- pygmt/src/grdtrack.py | 7 ++-- pygmt/src/text.py | 7 ++-- pygmt/tests/test_grdtrack.py | 4 +-- pygmt/tests/test_params_box.py | 4 +-- pygmt/tests/test_text.py | 9 +++-- 8 files changed, 60 insertions(+), 48 deletions(-) diff --git a/pygmt/exceptions.py b/pygmt/exceptions.py index 3a111e150df..ce18f9107bc 100644 --- a/pygmt/exceptions.py +++ b/pygmt/exceptions.py @@ -44,35 +44,6 @@ class GMTInvalidInput(GMTError): # noqa: N818 """ -class GMTParameterError(GMTError): - """ - Raised when parameters are missing or invalid. - - Parameters - ---------- - required - Names of required parameters. - reason - Detailed reason why the parameters are invalid. - """ - - def __init__( - self, - *, - required: set[str] | None = None, - reason: str | None = None, - ): - msg = [] - if required: - msg.append( - "Required parameter(s) are missing: " - f"{', '.join(repr(par) for par in required)}." - ) - if reason: - msg.append(reason) - super().__init__(" ".join(msg)) - - class GMTVersionError(GMTError): """ Raised when an incompatible version of GMT is being used. @@ -159,3 +130,34 @@ def __init__(self, dtype: object, /, reason: str | None = None): if reason: msg += f" {reason}" super().__init__(msg) + + +class GMTParameterError(GMTError): + """ + Raised when parameters are missing or invalid. + + Parameters + ---------- + required + Names of required parameters. + reason + Detailed reason why the parameters are invalid. + """ + + def __init__( + self, + *, + required: str | set[str] | None = None, + reason: str | None = None, + ): + msg = [] + if required: + if isinstance(required, str): + required = {required} + msg.append( + "Required parameter(s) are missing: " + f"{', '.join(repr(par) for par in required)}." + ) + if reason: + msg.append(reason) + super().__init__(" ".join(msg)) diff --git a/pygmt/helpers/validators.py b/pygmt/helpers/validators.py index 34a8e85e1b7..28a1954945d 100644 --- a/pygmt/helpers/validators.py +++ b/pygmt/helpers/validators.py @@ -6,7 +6,7 @@ from typing import Literal from pygmt._typing import PathLike -from pygmt.exceptions import GMTInvalidInput, GMTValueError +from pygmt.exceptions import GMTParameterError, GMTValueError def validate_output_table_type( @@ -43,7 +43,8 @@ def validate_output_table_type( >>> validate_output_table_type("file", outfile=None) Traceback (most recent call last): ... - pygmt.exceptions.GMTInvalidInput: Must specify 'outfile' for output_type='file'. + pygmt.exceptions.GMTParameterError: Required parameter(s) are missing: + ... 'outfile'. Must specify 'outfile' for output_type='file'. >>> with warnings.catch_warnings(record=True) as w: ... validate_output_table_type("pandas", outfile="not-none.txt") ... assert len(w) == 1 @@ -57,8 +58,9 @@ def validate_output_table_type( choices=_valids, ) if output_type == "file" and outfile is None: - msg = "Must specify 'outfile' for output_type='file'." - raise GMTInvalidInput(msg) + raise GMTParameterError( + required="outfile", reason="Must specify 'outfile' for output_type='file'." + ) if output_type != "file" and outfile is not None: msg = ( f"Changing 'output_type' from '{output_type}' to 'file' since 'outfile' " diff --git a/pygmt/params/box.py b/pygmt/params/box.py index 33b335d25d7..7fc160116ea 100644 --- a/pygmt/params/box.py +++ b/pygmt/params/box.py @@ -6,7 +6,7 @@ from collections.abc import Sequence from pygmt.alias import Alias -from pygmt.exceptions import GMTInvalidInput, GMTValueError +from pygmt.exceptions import GMTParameterError, GMTValueError from pygmt.helpers import is_nonstr_iter from pygmt.params.base import BaseParam @@ -65,8 +65,9 @@ def _validate(self): """ # inner_pen is required when inner_gap is set. if self.inner_gap is not None and self.inner_pen is None: - msg = "Parameter 'inner_pen' is required when 'inner_gap' is set." - raise GMTInvalidInput(msg) + raise GMTParameterError( + required="inner_pen", reason="is required when 'inner_gap' is set." + ) # shade_offset must be a sequence of two values or None. if self.shade_offset and not ( diff --git a/pygmt/src/grdtrack.py b/pygmt/src/grdtrack.py index 236cff1da8e..cb0201efc7d 100644 --- a/pygmt/src/grdtrack.py +++ b/pygmt/src/grdtrack.py @@ -11,7 +11,7 @@ from pygmt._typing import PathLike, TableLike from pygmt.alias import AliasSystem from pygmt.clib import Session -from pygmt.exceptions import GMTInvalidInput +from pygmt.exceptions import GMTInvalidInput, GMTParameterError from pygmt.helpers import ( build_arg_list, fmt_docstring, @@ -307,8 +307,9 @@ def grdtrack( raise GMTInvalidInput(msg) if hasattr(points, "columns") and newcolname is None: - msg = "Please pass in a str to 'newcolname'." - raise GMTInvalidInput(msg) + raise GMTParameterError( + required="newcolname", reason="Please pass in a str to 'newcolname'." + ) output_type = validate_output_table_type(output_type, outfile=outfile) diff --git a/pygmt/src/text.py b/pygmt/src/text.py index 156dd616a92..0f9a4890ed1 100644 --- a/pygmt/src/text.py +++ b/pygmt/src/text.py @@ -9,7 +9,7 @@ from pygmt._typing import AnchorCode, PathLike, StringArrayTypes, TableLike from pygmt.alias import Alias, AliasSystem from pygmt.clib import Session -from pygmt.exceptions import GMTInvalidInput, GMTTypeError +from pygmt.exceptions import GMTInvalidInput, GMTParameterError, GMTTypeError from pygmt.helpers import ( _check_encoding, build_arg_list, @@ -199,8 +199,9 @@ def text_( # noqa: PLR0912, PLR0913, PLR0915 if position is not None: if text is None: - msg = "'text' can't be None when 'position' is given." - raise GMTInvalidInput(msg) + raise GMTParameterError( + required="text", reason="'text' can't be None when 'position' is given." + ) if is_nonstr_iter(text): raise GMTTypeError( type(text), diff --git a/pygmt/tests/test_grdtrack.py b/pygmt/tests/test_grdtrack.py index 1b63dae041a..dfe5bd15f3c 100644 --- a/pygmt/tests/test_grdtrack.py +++ b/pygmt/tests/test_grdtrack.py @@ -9,7 +9,7 @@ import pandas as pd import pytest from pygmt import grdtrack -from pygmt.exceptions import GMTInvalidInput, GMTTypeError +from pygmt.exceptions import GMTInvalidInput, GMTParameterError, GMTTypeError from pygmt.helpers import GMTTempFile from pygmt.helpers.testing import load_static_earth_relief @@ -146,7 +146,7 @@ def test_grdtrack_without_newcolname_setting(dataarray, dataframe): """ Run grdtrack by not passing in newcolname parameter setting. """ - with pytest.raises(GMTInvalidInput): + with pytest.raises(GMTParameterError): grdtrack(points=dataframe, grid=dataarray) diff --git a/pygmt/tests/test_params_box.py b/pygmt/tests/test_params_box.py index 0bdd70adefe..ddea880aa28 100644 --- a/pygmt/tests/test_params_box.py +++ b/pygmt/tests/test_params_box.py @@ -3,7 +3,7 @@ """ import pytest -from pygmt.exceptions import GMTInvalidInput, GMTValueError +from pygmt.exceptions import GMTParameterError, GMTValueError from pygmt.params import Box @@ -55,5 +55,5 @@ def test_params_box_invalid_innerborder(): """ Test that inner_pen is required when inner_gap is set. """ - with pytest.raises(GMTInvalidInput): + with pytest.raises(GMTParameterError): _ = str(Box(inner_gap="2p")) diff --git a/pygmt/tests/test_text.py b/pygmt/tests/test_text.py index 75003409ce0..931f1a18554 100644 --- a/pygmt/tests/test_text.py +++ b/pygmt/tests/test_text.py @@ -7,7 +7,12 @@ import numpy as np import pytest from pygmt import Figure, config -from pygmt.exceptions import GMTCLibError, GMTInvalidInput, GMTTypeError +from pygmt.exceptions import ( + GMTCLibError, + GMTInvalidInput, + GMTParameterError, + GMTTypeError, +) from pygmt.helpers import GMTTempFile from pygmt.helpers.testing import skip_if_no @@ -152,7 +157,7 @@ def test_text_invalid_inputs(region): ) with pytest.raises(GMTInvalidInput): fig.text(region=region, projection="x1c", textfiles="file.txt", text="text") - with pytest.raises(GMTInvalidInput): + with pytest.raises(GMTParameterError): fig.text(region=region, projection="x1c", position="MC", text=None) with pytest.raises(GMTTypeError): fig.text( From db5d047db5a3cf0c0de288cd4a42727423c4d827 Mon Sep 17 00:00:00 2001 From: chuan Date: Wed, 28 Jan 2026 20:18:07 +0800 Subject: [PATCH 06/26] fix doctest and check GMTParameterError --- pygmt/helpers/validators.py | 3 +-- pygmt/tests/test_grdtrack.py | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/pygmt/helpers/validators.py b/pygmt/helpers/validators.py index 28a1954945d..063dbe4bec7 100644 --- a/pygmt/helpers/validators.py +++ b/pygmt/helpers/validators.py @@ -43,8 +43,7 @@ def validate_output_table_type( >>> validate_output_table_type("file", outfile=None) Traceback (most recent call last): ... - pygmt.exceptions.GMTParameterError: Required parameter(s) are missing: - ... 'outfile'. Must specify 'outfile' for output_type='file'. + pygmt.exceptions.GMTParameterError: Required parameter(s) are missing: 'outfile'... >>> with warnings.catch_warnings(record=True) as w: ... validate_output_table_type("pandas", outfile="not-none.txt") ... assert len(w) == 1 diff --git a/pygmt/tests/test_grdtrack.py b/pygmt/tests/test_grdtrack.py index dfe5bd15f3c..c6d45958094 100644 --- a/pygmt/tests/test_grdtrack.py +++ b/pygmt/tests/test_grdtrack.py @@ -154,7 +154,7 @@ def test_grdtrack_without_outfile_setting(dataarray, dataframe): """ Run grdtrack by not passing in outfile parameter setting. """ - with pytest.raises(GMTInvalidInput): + with pytest.raises(GMTParameterError): grdtrack(points=dataframe, grid=dataarray) From c5d26b2fea40beec3519c01158a75690d33b7900 Mon Sep 17 00:00:00 2001 From: Xingchen He Date: Thu, 29 Jan 2026 12:25:18 +0800 Subject: [PATCH 07/26] Update pygmt/exceptions.py Co-authored-by: Dongdong Tian --- pygmt/exceptions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pygmt/exceptions.py b/pygmt/exceptions.py index ce18f9107bc..7ee839c2aee 100644 --- a/pygmt/exceptions.py +++ b/pygmt/exceptions.py @@ -139,7 +139,7 @@ class GMTParameterError(GMTError): Parameters ---------- required - Names of required parameters. + Name or a set of names of required parameters. reason Detailed reason why the parameters are invalid. """ From c6c4b7f5d0083833be24a220e7de82c94f6a093b Mon Sep 17 00:00:00 2001 From: chuan Date: Thu, 29 Jan 2026 12:28:09 +0800 Subject: [PATCH 08/26] sort all the exceptions alphabetically --- doc/api/index.rst | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/doc/api/index.rst b/doc/api/index.rst index 73acdfb9039..258e2b40070 100644 --- a/doc/api/index.rst +++ b/doc/api/index.rst @@ -293,15 +293,15 @@ All custom exceptions are derived from :class:`pygmt.exceptions.GMTError`. :toctree: generated exceptions.GMTError - exceptions.GMTInvalidInput - exceptions.GMTParameterError - exceptions.GMTVersionError - exceptions.GMTOSError exceptions.GMTCLibError exceptions.GMTCLibNoSessionError exceptions.GMTCLibNotFoundError + exceptions.GMTInvalidInput + exceptions.GMTOSError + exceptions.GMTParameterError exceptions.GMTTypeError exceptions.GMTValueError + exceptions.GMTVersionError .. currentmodule:: pygmt From f9ffe43c94d56ddfbc47962ccb024391e3cb753a Mon Sep 17 00:00:00 2001 From: Xingchen He Date: Thu, 29 Jan 2026 20:58:31 +0800 Subject: [PATCH 09/26] Update pygmt/exceptions.py Co-authored-by: Dongdong Tian --- pygmt/exceptions.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/pygmt/exceptions.py b/pygmt/exceptions.py index 7ee839c2aee..eccb08d74ff 100644 --- a/pygmt/exceptions.py +++ b/pygmt/exceptions.py @@ -153,11 +153,12 @@ def __init__( msg = [] if required: if isinstance(required, str): - required = {required} - msg.append( - "Required parameter(s) are missing: " - f"{', '.join(repr(par) for par in required)}." - ) + msg.append(f"Missing required parameter: {par!r}.") + else: + msg.append( + "Missing required parameters: " + f"{', '.join(repr(par) for par in required)}." + ) if reason: msg.append(reason) super().__init__(" ".join(msg)) From 3904c569016540ac3b9814118c5d2dd8ff4d3eeb Mon Sep 17 00:00:00 2001 From: Xingchen He Date: Thu, 29 Jan 2026 20:59:05 +0800 Subject: [PATCH 10/26] Update pygmt/helpers/validators.py Co-authored-by: Dongdong Tian --- pygmt/helpers/validators.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pygmt/helpers/validators.py b/pygmt/helpers/validators.py index 063dbe4bec7..35aadbe19f9 100644 --- a/pygmt/helpers/validators.py +++ b/pygmt/helpers/validators.py @@ -58,7 +58,7 @@ def validate_output_table_type( ) if output_type == "file" and outfile is None: raise GMTParameterError( - required="outfile", reason="Must specify 'outfile' for output_type='file'." + required="outfile", reason="Required when output_type='file'." ) if output_type != "file" and outfile is not None: msg = ( From b08f26a7b5f482937c50519251f6c21767afa9fb Mon Sep 17 00:00:00 2001 From: Xingchen He Date: Thu, 29 Jan 2026 20:59:13 +0800 Subject: [PATCH 11/26] Update pygmt/params/box.py Co-authored-by: Dongdong Tian --- pygmt/params/box.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pygmt/params/box.py b/pygmt/params/box.py index 7fc160116ea..0cf23e4b562 100644 --- a/pygmt/params/box.py +++ b/pygmt/params/box.py @@ -66,7 +66,7 @@ def _validate(self): # inner_pen is required when inner_gap is set. if self.inner_gap is not None and self.inner_pen is None: raise GMTParameterError( - required="inner_pen", reason="is required when 'inner_gap' is set." + required="inner_pen", reason="Required when 'inner_gap' is set." ) # shade_offset must be a sequence of two values or None. From 18975aa1ba6631f57eda0a1a364d054cb665544c Mon Sep 17 00:00:00 2001 From: Xingchen He Date: Thu, 29 Jan 2026 20:59:26 +0800 Subject: [PATCH 12/26] Update pygmt/src/text.py Co-authored-by: Dongdong Tian --- pygmt/src/text.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pygmt/src/text.py b/pygmt/src/text.py index 0f9a4890ed1..e2b46ab34cd 100644 --- a/pygmt/src/text.py +++ b/pygmt/src/text.py @@ -200,7 +200,7 @@ def text_( # noqa: PLR0912, PLR0913, PLR0915 if position is not None: if text is None: raise GMTParameterError( - required="text", reason="'text' can't be None when 'position' is given." + required="text", reason="Required when 'position' is given." ) if is_nonstr_iter(text): raise GMTTypeError( From f113ebd49d3ac01a18c71979e124075713051a31 Mon Sep 17 00:00:00 2001 From: chuan Date: Thu, 29 Jan 2026 21:07:35 +0800 Subject: [PATCH 13/26] fix typo in GMTParameterError --- pygmt/exceptions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pygmt/exceptions.py b/pygmt/exceptions.py index eccb08d74ff..93b80bb082b 100644 --- a/pygmt/exceptions.py +++ b/pygmt/exceptions.py @@ -153,7 +153,7 @@ def __init__( msg = [] if required: if isinstance(required, str): - msg.append(f"Missing required parameter: {par!r}.") + msg.append(f"Missing required parameter: {required!r}.") else: msg.append( "Missing required parameters: " From a7fadb5a47043ce6ff8dc4aadd16750355ffe666 Mon Sep 17 00:00:00 2001 From: Xingchen He Date: Thu, 29 Jan 2026 21:08:17 +0800 Subject: [PATCH 14/26] Update pygmt/helpers/validators.py Co-authored-by: Dongdong Tian --- pygmt/helpers/validators.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pygmt/helpers/validators.py b/pygmt/helpers/validators.py index 35aadbe19f9..cd6553bd30d 100644 --- a/pygmt/helpers/validators.py +++ b/pygmt/helpers/validators.py @@ -43,7 +43,7 @@ def validate_output_table_type( >>> validate_output_table_type("file", outfile=None) Traceback (most recent call last): ... - pygmt.exceptions.GMTParameterError: Required parameter(s) are missing: 'outfile'... + pygmt.exceptions.GMTParameterError: Missing required parameter: 'outfile'. Required... >>> with warnings.catch_warnings(record=True) as w: ... validate_output_table_type("pandas", outfile="not-none.txt") ... assert len(w) == 1 From 22a4b3942a0989328dfeb9dd7342883a588b3bc6 Mon Sep 17 00:00:00 2001 From: Xingchen He Date: Thu, 29 Jan 2026 21:08:25 +0800 Subject: [PATCH 15/26] Update pygmt/src/text.py Co-authored-by: Dongdong Tian --- pygmt/src/text.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pygmt/src/text.py b/pygmt/src/text.py index e2b46ab34cd..b6d7be586fe 100644 --- a/pygmt/src/text.py +++ b/pygmt/src/text.py @@ -200,7 +200,7 @@ def text_( # noqa: PLR0912, PLR0913, PLR0915 if position is not None: if text is None: raise GMTParameterError( - required="text", reason="Required when 'position' is given." + required="text", reason="Required when 'position' is set." ) if is_nonstr_iter(text): raise GMTTypeError( From 1b8fe43ce441253d496c1eb118a1eb3a563a913a Mon Sep 17 00:00:00 2001 From: Xingchen He Date: Thu, 29 Jan 2026 21:08:33 +0800 Subject: [PATCH 16/26] Update pygmt/src/grdtrack.py Co-authored-by: Dongdong Tian --- pygmt/src/grdtrack.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pygmt/src/grdtrack.py b/pygmt/src/grdtrack.py index cb0201efc7d..ed4c04bcb94 100644 --- a/pygmt/src/grdtrack.py +++ b/pygmt/src/grdtrack.py @@ -308,7 +308,7 @@ def grdtrack( if hasattr(points, "columns") and newcolname is None: raise GMTParameterError( - required="newcolname", reason="Please pass in a str to 'newcolname'." + required="newcolname", reason="Pass in a string to 'newcolname'." ) output_type = validate_output_table_type(output_type, outfile=outfile) From 7235041c6bfe13c71ebd0ff95652b5c07cc44a00 Mon Sep 17 00:00:00 2001 From: chuan Date: Thu, 29 Jan 2026 21:12:24 +0800 Subject: [PATCH 17/26] fix format --- pygmt/helpers/validators.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pygmt/helpers/validators.py b/pygmt/helpers/validators.py index cd6553bd30d..e0044a51dc0 100644 --- a/pygmt/helpers/validators.py +++ b/pygmt/helpers/validators.py @@ -43,7 +43,7 @@ def validate_output_table_type( >>> validate_output_table_type("file", outfile=None) Traceback (most recent call last): ... - pygmt.exceptions.GMTParameterError: Missing required parameter: 'outfile'. Required... + pygmt.exceptions.GMTParameterError: Missing required parameter: 'outfile'. ... >>> with warnings.catch_warnings(record=True) as w: ... validate_output_table_type("pandas", outfile="not-none.txt") ... assert len(w) == 1 From ab642f967db3132cd10fbac326fba3965630d2d8 Mon Sep 17 00:00:00 2001 From: chuan Date: Thu, 29 Jan 2026 21:39:01 +0800 Subject: [PATCH 18/26] change GMTInvalidInput to GMTParameterError in filter1d, grdlandmask, grdproject, meca, project, sphdistance, text, velo, xyz2grd --- pygmt/src/filter1d.py | 5 ++--- pygmt/src/grdlandmask.py | 5 ++--- pygmt/src/grdproject.py | 5 ++--- pygmt/src/meca.py | 5 ++--- pygmt/src/project.py | 5 ++--- pygmt/src/sphdistance.py | 5 ++--- pygmt/src/text.py | 5 +++-- pygmt/src/velo.py | 14 ++++++++------ pygmt/src/xyz2grd.py | 5 ++--- 9 files changed, 25 insertions(+), 29 deletions(-) diff --git a/pygmt/src/filter1d.py b/pygmt/src/filter1d.py index edad413c990..92aa8b49cdf 100644 --- a/pygmt/src/filter1d.py +++ b/pygmt/src/filter1d.py @@ -9,7 +9,7 @@ from pygmt._typing import PathLike, TableLike from pygmt.alias import AliasSystem from pygmt.clib import Session -from pygmt.exceptions import GMTInvalidInput +from pygmt.exceptions import GMTParameterError from pygmt.helpers import ( build_arg_list, fmt_docstring, @@ -112,8 +112,7 @@ def filter1d( (depends on ``output_type``) """ if kwargs.get("F") is None: - msg = "Pass a required argument to 'filter_type'." - raise GMTInvalidInput(msg) + raise GMTParameterError(required="filter_type") output_type = validate_output_table_type(output_type, outfile=outfile) diff --git a/pygmt/src/grdlandmask.py b/pygmt/src/grdlandmask.py index b6f6721cd96..09c8f9807b6 100644 --- a/pygmt/src/grdlandmask.py +++ b/pygmt/src/grdlandmask.py @@ -9,7 +9,7 @@ from pygmt._typing import PathLike from pygmt.alias import Alias, AliasSystem from pygmt.clib import Session -from pygmt.exceptions import GMTInvalidInput +from pygmt.exceptions import GMTParameterError from pygmt.helpers import build_arg_list, deprecate_parameter, fmt_docstring, use_alias __doctest_skip__ = ["grdlandmask"] @@ -118,8 +118,7 @@ def grdlandmask( >>> landmask = pygmt.grdlandmask(spacing=1, region=[125, 130, 30, 35]) """ if kwargs.get("I", spacing) is None or kwargs.get("R", region) is None: - msg = "Both 'region' and 'spacing' must be specified." - raise GMTInvalidInput(msg) + raise GMTParameterError(required={"region", "spacing"}) aliasdict = AliasSystem( D=Alias( diff --git a/pygmt/src/grdproject.py b/pygmt/src/grdproject.py index de8fd12c8a5..e2d2a3a9824 100644 --- a/pygmt/src/grdproject.py +++ b/pygmt/src/grdproject.py @@ -9,7 +9,7 @@ from pygmt._typing import PathLike from pygmt.alias import Alias, AliasSystem from pygmt.clib import Session -from pygmt.exceptions import GMTInvalidInput +from pygmt.exceptions import GMTInvalidInput, GMTParameterError from pygmt.helpers import build_arg_list, fmt_docstring, use_alias __doctest_skip__ = ["grdproject"] @@ -117,8 +117,7 @@ def grdproject( # noqa: PLR0913 >>> new_grid = pygmt.grdproject(grid=grid, projection="M10c", region=region) """ if kwargs.get("J", projection) is None: - msg = "Parameter 'projection' must be specified." - raise GMTInvalidInput(msg) + raise GMTParameterError(required="projection") if kwargs.get("M", unit) is not None and kwargs.get("F", scaling) is not False: msg = "Cannot use both 'unit' and 'scaling'." diff --git a/pygmt/src/meca.py b/pygmt/src/meca.py index 56c63037286..661082adc74 100644 --- a/pygmt/src/meca.py +++ b/pygmt/src/meca.py @@ -10,7 +10,7 @@ from pygmt._typing import PathLike, TableLike from pygmt.alias import Alias, AliasSystem from pygmt.clib import Session -from pygmt.exceptions import GMTInvalidInput, GMTValueError +from pygmt.exceptions import GMTParameterError, GMTValueError from pygmt.helpers import ( build_arg_list, data_kind, @@ -31,8 +31,7 @@ def _get_focal_convention(spec, convention, component) -> _FocalMechanismConvent # Determine the convention from the 'convention' parameter. if convention is None: - msg = "Parameter 'convention' must be specified." - raise GMTInvalidInput(msg) + raise GMTParameterError(required="convention") return _FocalMechanismConvention(convention=convention, component=component) diff --git a/pygmt/src/project.py b/pygmt/src/project.py index ad88345d1cb..af41331e0df 100644 --- a/pygmt/src/project.py +++ b/pygmt/src/project.py @@ -10,7 +10,7 @@ from pygmt._typing import PathLike, TableLike from pygmt.alias import Alias, AliasSystem from pygmt.clib import Session -from pygmt.exceptions import GMTInvalidInput +from pygmt.exceptions import GMTInvalidInput, GMTParameterError from pygmt.helpers import ( build_arg_list, fmt_docstring, @@ -221,8 +221,7 @@ def project( # noqa: PLR0913 (depends on ``output_type``) """ if kwargs.get("C", center) is None: - msg = "Parameter 'center' must be specified." - raise GMTInvalidInput(msg) + raise GMTParameterError(required="center") if kwargs.get("G") is None and data is None: msg = "The 'data' parameter must be specified unless 'generate' is used." raise GMTInvalidInput(msg) diff --git a/pygmt/src/sphdistance.py b/pygmt/src/sphdistance.py index 6d4af6c46ec..57927b5fd81 100644 --- a/pygmt/src/sphdistance.py +++ b/pygmt/src/sphdistance.py @@ -10,7 +10,7 @@ from pygmt._typing import PathLike, TableLike from pygmt.alias import Alias, AliasSystem from pygmt.clib import Session -from pygmt.exceptions import GMTInvalidInput +from pygmt.exceptions import GMTParameterError from pygmt.helpers import build_arg_list, fmt_docstring, use_alias __doctest_skip__ = ["sphdistance"] @@ -122,8 +122,7 @@ def sphdistance( ... ) """ if kwargs.get("I", spacing) is None or kwargs.get("R", region) is None: - msg = "Both 'region' and 'spacing' must be specified." - raise GMTInvalidInput(msg) + raise GMTParameterError(required={"region", "spacing"}) aliasdict = AliasSystem( I=Alias(spacing, name="spacing", sep="/", size=2), diff --git a/pygmt/src/text.py b/pygmt/src/text.py index b6d7be586fe..8bbe324322b 100644 --- a/pygmt/src/text.py +++ b/pygmt/src/text.py @@ -212,8 +212,9 @@ def text_( # noqa: PLR0912, PLR0913, PLR0915 msg = "'text' can't be specified when 'textfiles' is given." raise GMTInvalidInput(msg) if kind == "empty" and text is None: - msg = "Must provide text with x/y pairs." - raise GMTInvalidInput(msg) + raise GMTParameterError( + required="text", reason="Must provide text with x/y pairs." + ) # Arguments that can accept arrays. array_args = [ diff --git a/pygmt/src/velo.py b/pygmt/src/velo.py index d1013f582e9..2ae5758452a 100644 --- a/pygmt/src/velo.py +++ b/pygmt/src/velo.py @@ -10,7 +10,7 @@ from pygmt._typing import PathLike, TableLike from pygmt.alias import Alias, AliasSystem from pygmt.clib import Session -from pygmt.exceptions import GMTInvalidInput, GMTTypeError +from pygmt.exceptions import GMTParameterError, GMTTypeError from pygmt.helpers import build_arg_list, deprecate_parameter, fmt_docstring, use_alias @@ -256,11 +256,13 @@ def velo( # noqa : PLR0913 """ self._activate_figure() - if kwargs.get("S") is None or ( - kwargs.get("S") is not None and not isinstance(kwargs["S"], str) - ): - msg = "The parameter 'spec' is required and has to be a string." - raise GMTInvalidInput(msg) + if kwargs.get("S") is None: + raise GMTParameterError(required="spec") + if not isinstance(kwargs["S"], str): + raise GMTTypeError( + type(kwargs["S"]), + reason="The parameter 'spec' has to be a string.", + ) if isinstance(data, np.ndarray) and not pd.api.types.is_numeric_dtype(data): raise GMTTypeError( diff --git a/pygmt/src/xyz2grd.py b/pygmt/src/xyz2grd.py index ab1f9f59b10..c7334ede9e5 100644 --- a/pygmt/src/xyz2grd.py +++ b/pygmt/src/xyz2grd.py @@ -9,7 +9,7 @@ from pygmt._typing import PathLike, TableLike from pygmt.alias import Alias, AliasSystem from pygmt.clib import Session -from pygmt.exceptions import GMTInvalidInput +from pygmt.exceptions import GMTParameterError from pygmt.helpers import build_arg_list, fmt_docstring, use_alias __doctest_skip__ = ["xyz2grd"] @@ -158,8 +158,7 @@ def xyz2grd( ... ) """ if kwargs.get("I", spacing) is None or kwargs.get("R", region) is None: - msg = "Both 'region' and 'spacing' must be specified." - raise GMTInvalidInput(msg) + raise GMTParameterError(required={"region", "spacing"}) aliasdict = AliasSystem( I=Alias(spacing, name="spacing", sep="/", size=2), From 7b3e955f673dc41663fbf7ffc6b59c925546f507 Mon Sep 17 00:00:00 2001 From: Xingchen He Date: Fri, 30 Jan 2026 09:03:52 +0800 Subject: [PATCH 19/26] Update pygmt/src/project.py Co-authored-by: Dongdong Tian --- pygmt/src/project.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pygmt/src/project.py b/pygmt/src/project.py index af41331e0df..1c8898a7b2f 100644 --- a/pygmt/src/project.py +++ b/pygmt/src/project.py @@ -223,8 +223,7 @@ def project( # noqa: PLR0913 if kwargs.get("C", center) is None: raise GMTParameterError(required="center") if kwargs.get("G") is None and data is None: - msg = "The 'data' parameter must be specified unless 'generate' is used." - raise GMTInvalidInput(msg) + raise GMTParameterError(required="data", reason="Required unless 'generate' is set.") if kwargs.get("G") is not None and kwargs.get("F") is not None: msg = "The 'convention' parameter is not allowed with 'generate'." raise GMTInvalidInput(msg) From 99c6b04c30fc246905d6cc01240dbf4000c2c699 Mon Sep 17 00:00:00 2001 From: Xingchen He Date: Fri, 30 Jan 2026 09:04:09 +0800 Subject: [PATCH 20/26] Update pygmt/src/velo.py Co-authored-by: Dongdong Tian --- pygmt/src/velo.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pygmt/src/velo.py b/pygmt/src/velo.py index 2ae5758452a..dbdd37a8c26 100644 --- a/pygmt/src/velo.py +++ b/pygmt/src/velo.py @@ -261,7 +261,7 @@ def velo( # noqa : PLR0913 if not isinstance(kwargs["S"], str): raise GMTTypeError( type(kwargs["S"]), - reason="The parameter 'spec' has to be a string.", + reason="Parameter 'spec' must be in string type.", ) if isinstance(data, np.ndarray) and not pd.api.types.is_numeric_dtype(data): From 40942f00639d464878d9e3bc5fb6a3a4b956eba8 Mon Sep 17 00:00:00 2001 From: Xingchen He Date: Fri, 30 Jan 2026 09:04:21 +0800 Subject: [PATCH 21/26] Update pygmt/src/text.py Co-authored-by: Dongdong Tian --- pygmt/src/text.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pygmt/src/text.py b/pygmt/src/text.py index 8bbe324322b..7f3f2b2b9c8 100644 --- a/pygmt/src/text.py +++ b/pygmt/src/text.py @@ -213,7 +213,7 @@ def text_( # noqa: PLR0912, PLR0913, PLR0915 raise GMTInvalidInput(msg) if kind == "empty" and text is None: raise GMTParameterError( - required="text", reason="Must provide text with x/y pairs." + required="text", reason="Required when 'x' and 'y' are set." ) # Arguments that can accept arrays. From 9ceec0803cf2796193b0f1c3cf9328a5839006a8 Mon Sep 17 00:00:00 2001 From: chuan Date: Fri, 30 Jan 2026 09:18:41 +0800 Subject: [PATCH 22/26] update GMTParameterError for load_remote_dataset, grdgradient, histogram, inset, magnetic_rose, project --- pygmt/datasets/load_remote_dataset.py | 9 ++++----- pygmt/src/grdgradient.py | 7 ++++--- pygmt/src/histogram.py | 7 ++++--- pygmt/src/inset.py | 8 +++++--- pygmt/src/magnetic_rose.py | 8 +++++--- pygmt/src/project.py | 4 +++- 6 files changed, 25 insertions(+), 18 deletions(-) diff --git a/pygmt/datasets/load_remote_dataset.py b/pygmt/datasets/load_remote_dataset.py index 3318602a247..0a059c8f26c 100644 --- a/pygmt/datasets/load_remote_dataset.py +++ b/pygmt/datasets/load_remote_dataset.py @@ -7,7 +7,7 @@ from typing import Any, Literal, NamedTuple import xarray as xr -from pygmt.exceptions import GMTInvalidInput, GMTValueError +from pygmt.exceptions import GMTParameterError, GMTValueError with contextlib.suppress(ImportError): # rioxarray is needed to register the rio accessor @@ -564,11 +564,10 @@ def _load_remote_dataset( reg = registration[0] if resinfo.tiled and region is None: - msg = ( - f"The 'region' parameter is required for {dataset.description} " - f"resolution '{resolution}'." + raise GMTParameterError( + required="region", + reason=f"Required for {dataset.description} resolution '{resolution}'.", ) - raise GMTInvalidInput(msg) fname = f"@{prefix}_{resolution}_{reg}" grid = xr.load_dataarray( diff --git a/pygmt/src/grdgradient.py b/pygmt/src/grdgradient.py index 7f90fec60af..f7641a5af44 100644 --- a/pygmt/src/grdgradient.py +++ b/pygmt/src/grdgradient.py @@ -9,7 +9,7 @@ from pygmt._typing import PathLike from pygmt.alias import Alias, AliasSystem from pygmt.clib import Session -from pygmt.exceptions import GMTInvalidInput +from pygmt.exceptions import GMTInvalidInput, GMTParameterError from pygmt.helpers import build_arg_list, fmt_docstring, use_alias __doctest_skip__ = ["grdgradient"] @@ -166,8 +166,9 @@ def grdgradient( >>> new_grid = pygmt.grdgradient(grid=grid, azimuth=10) """ if kwargs.get("Q") is not None and kwargs.get("N") is None: - msg = "Must specify normalize if tiles is specified." - raise GMTInvalidInput(msg) + raise GMTParameterError( + required="normalize", reason="Required when 'Q' is set." + ) if ( kwargs.get("A", azimuth) is None and kwargs.get("D") is None diff --git a/pygmt/src/histogram.py b/pygmt/src/histogram.py index 349bf23d62a..61660b1f538 100644 --- a/pygmt/src/histogram.py +++ b/pygmt/src/histogram.py @@ -8,7 +8,7 @@ from pygmt._typing import PathLike, TableLike from pygmt.alias import Alias, AliasSystem from pygmt.clib import Session -from pygmt.exceptions import GMTInvalidInput +from pygmt.exceptions import GMTParameterError from pygmt.helpers import ( build_arg_list, deprecate_parameter, @@ -163,8 +163,9 @@ def histogram( # noqa: PLR0913 self._activate_figure() if bar_offset is not None and bar_width is None: - msg = "Setting 'bar_offset' requires setting 'bar_width'." - raise GMTInvalidInput(msg) + raise GMTParameterError( + required="bar_width", reason="Required when 'bar_offset' is set." + ) aliasdict = AliasSystem( E=[ diff --git a/pygmt/src/inset.py b/pygmt/src/inset.py index 1b7d9367bcb..80c66f5fe6b 100644 --- a/pygmt/src/inset.py +++ b/pygmt/src/inset.py @@ -9,7 +9,7 @@ from pygmt._typing import AnchorCode from pygmt.alias import Alias, AliasSystem from pygmt.clib import Session -from pygmt.exceptions import GMTInvalidInput +from pygmt.exceptions import GMTParameterError from pygmt.helpers import ( build_arg_list, deprecate_parameter, @@ -139,8 +139,10 @@ def inset( and width is None and (projection is None or region is None) ): - msg = "Parameter 'width' must be specified." - raise GMTInvalidInput(msg) + raise GMTParameterError( + required="width", + reason="Required when position is not a string and both projection and region are not set.", + ) aliasdict = AliasSystem( D=[ diff --git a/pygmt/src/magnetic_rose.py b/pygmt/src/magnetic_rose.py index e91ef24c1af..10c1b173668 100644 --- a/pygmt/src/magnetic_rose.py +++ b/pygmt/src/magnetic_rose.py @@ -8,7 +8,7 @@ from pygmt._typing import AnchorCode from pygmt.alias import Alias, AliasSystem from pygmt.clib import Session -from pygmt.exceptions import GMTInvalidInput +from pygmt.exceptions import GMTParameterError from pygmt.helpers import build_arg_list, fmt_docstring from pygmt.params import Box, Position from pygmt.src._common import _parse_position @@ -111,8 +111,10 @@ def magnetic_rose( # noqa: PLR0913 position = _parse_position(position, default=Position("BL", cstype="inside")) if declination_label is not None and declination is None: - msg = "Parameter 'declination' must be set when 'declination_label' is set." - raise GMTInvalidInput(msg) + raise GMTParameterError( + required="declination", + reason="Required when 'declination_label' is set.", + ) aliasdict = AliasSystem( F=Alias(box, name="box"), diff --git a/pygmt/src/project.py b/pygmt/src/project.py index 1c8898a7b2f..2dc069b644a 100644 --- a/pygmt/src/project.py +++ b/pygmt/src/project.py @@ -223,7 +223,9 @@ def project( # noqa: PLR0913 if kwargs.get("C", center) is None: raise GMTParameterError(required="center") if kwargs.get("G") is None and data is None: - raise GMTParameterError(required="data", reason="Required unless 'generate' is set.") + raise GMTParameterError( + required="data", reason="Required unless 'generate' is set." + ) if kwargs.get("G") is not None and kwargs.get("F") is not None: msg = "The 'convention' parameter is not allowed with 'generate'." raise GMTInvalidInput(msg) From 784c5cd4abe5d4a28a44ded535adc511bf995e74 Mon Sep 17 00:00:00 2001 From: Xingchen He Date: Fri, 30 Jan 2026 09:27:22 +0800 Subject: [PATCH 23/26] Update pygmt/datasets/load_remote_dataset.py Co-authored-by: Dongdong Tian --- pygmt/datasets/load_remote_dataset.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pygmt/datasets/load_remote_dataset.py b/pygmt/datasets/load_remote_dataset.py index 0a059c8f26c..1accad95d9d 100644 --- a/pygmt/datasets/load_remote_dataset.py +++ b/pygmt/datasets/load_remote_dataset.py @@ -566,7 +566,7 @@ def _load_remote_dataset( if resinfo.tiled and region is None: raise GMTParameterError( required="region", - reason=f"Required for {dataset.description} resolution '{resolution}'.", + reason=f"Required for {dataset.description} resolution {resolution!r}.", ) fname = f"@{prefix}_{resolution}_{reg}" From 04c8a8dfd78eaf8047810398ae3eb2ba201b697a Mon Sep 17 00:00:00 2001 From: Xingchen He Date: Fri, 30 Jan 2026 09:27:35 +0800 Subject: [PATCH 24/26] Update pygmt/src/grdgradient.py Co-authored-by: Dongdong Tian --- pygmt/src/grdgradient.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pygmt/src/grdgradient.py b/pygmt/src/grdgradient.py index f7641a5af44..6036cc54f56 100644 --- a/pygmt/src/grdgradient.py +++ b/pygmt/src/grdgradient.py @@ -167,7 +167,7 @@ def grdgradient( """ if kwargs.get("Q") is not None and kwargs.get("N") is None: raise GMTParameterError( - required="normalize", reason="Required when 'Q' is set." + required="normalize", reason="Required when 'tiles' is set." ) if ( kwargs.get("A", azimuth) is None From 9981c91bfc69d687088264a9f28508b36d8c29e4 Mon Sep 17 00:00:00 2001 From: Xingchen He Date: Fri, 30 Jan 2026 09:27:59 +0800 Subject: [PATCH 25/26] Update pygmt/src/inset.py Co-authored-by: Dongdong Tian --- pygmt/src/inset.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pygmt/src/inset.py b/pygmt/src/inset.py index 80c66f5fe6b..d8d83a85f77 100644 --- a/pygmt/src/inset.py +++ b/pygmt/src/inset.py @@ -141,7 +141,7 @@ def inset( ): raise GMTParameterError( required="width", - reason="Required when position is not a string and both projection and region are not set.", + reason="Required unless 'projection' and 'region' are set.", ) aliasdict = AliasSystem( From fba11bd4b37bda67f2a89536d58d4eedbcbbb535 Mon Sep 17 00:00:00 2001 From: chuan Date: Fri, 30 Jan 2026 10:15:01 +0800 Subject: [PATCH 26/26] fix test check for GMTParameterError --- pygmt/tests/test_datasets_load_remote_datasets.py | 4 ++-- pygmt/tests/test_grdgradient.py | 4 ++-- pygmt/tests/test_grdlandmask.py | 4 ++-- pygmt/tests/test_grdproject.py | 4 ++-- pygmt/tests/test_histogram.py | 4 ++-- pygmt/tests/test_inset.py | 6 +++--- pygmt/tests/test_magnetic_rose.py | 4 ++-- pygmt/tests/test_meca.py | 4 ++-- pygmt/tests/test_project.py | 6 +++--- pygmt/tests/test_sphdistance.py | 4 ++-- pygmt/tests/test_text.py | 2 +- pygmt/tests/test_velo.py | 4 ++-- pygmt/tests/test_xyz2grd.py | 8 ++++---- 13 files changed, 29 insertions(+), 29 deletions(-) diff --git a/pygmt/tests/test_datasets_load_remote_datasets.py b/pygmt/tests/test_datasets_load_remote_datasets.py index e2cef8f8ac2..dfa7fc5bf75 100644 --- a/pygmt/tests/test_datasets_load_remote_datasets.py +++ b/pygmt/tests/test_datasets_load_remote_datasets.py @@ -5,7 +5,7 @@ import pytest from pygmt.datasets.load_remote_dataset import _load_remote_dataset from pygmt.enums import GridRegistration -from pygmt.exceptions import GMTInvalidInput, GMTValueError +from pygmt.exceptions import GMTParameterError, GMTValueError def load_remote_dataset_wrapper(resolution="01d", region=None, registration=None): @@ -61,7 +61,7 @@ def test_load_remote_dataset_tiled_grid_without_region(): Make sure _load_remote_dataset fails when trying to load a tiled grid without specifying a region. """ - with pytest.raises(GMTInvalidInput): + with pytest.raises(GMTParameterError): load_remote_dataset_wrapper(resolution="01m") diff --git a/pygmt/tests/test_grdgradient.py b/pygmt/tests/test_grdgradient.py index 5749b237aea..130ce64ccac 100644 --- a/pygmt/tests/test_grdgradient.py +++ b/pygmt/tests/test_grdgradient.py @@ -8,7 +8,7 @@ import xarray as xr from pygmt import grdgradient from pygmt.enums import GridRegistration, GridType -from pygmt.exceptions import GMTInvalidInput +from pygmt.exceptions import GMTInvalidInput, GMTParameterError from pygmt.helpers import GMTTempFile from pygmt.helpers.testing import load_static_earth_relief @@ -82,6 +82,6 @@ def test_grdgradient_fails(grid): """ with pytest.raises(GMTInvalidInput): grdgradient(grid=grid) # fails without required arguments - with pytest.raises(GMTInvalidInput): + with pytest.raises(GMTParameterError): # fails when tiles is specified but not normalize grdgradient(grid=grid, azimuth=10, direction="c", tiles="c") diff --git a/pygmt/tests/test_grdlandmask.py b/pygmt/tests/test_grdlandmask.py index 21b45d8d8c5..9155890c414 100644 --- a/pygmt/tests/test_grdlandmask.py +++ b/pygmt/tests/test_grdlandmask.py @@ -8,7 +8,7 @@ import xarray as xr from pygmt import grdlandmask from pygmt.enums import GridRegistration, GridType -from pygmt.exceptions import GMTInvalidInput +from pygmt.exceptions import GMTParameterError from pygmt.helpers import GMTTempFile @@ -64,5 +64,5 @@ def test_grdlandmask_fails(): """ Check that grdlandmask fails correctly when region and spacing are not given. """ - with pytest.raises(GMTInvalidInput): + with pytest.raises(GMTParameterError): grdlandmask() diff --git a/pygmt/tests/test_grdproject.py b/pygmt/tests/test_grdproject.py index 8a5560448c5..4207b4a4521 100644 --- a/pygmt/tests/test_grdproject.py +++ b/pygmt/tests/test_grdproject.py @@ -8,7 +8,7 @@ import xarray as xr from pygmt import grdproject from pygmt.enums import GridRegistration, GridType -from pygmt.exceptions import GMTInvalidInput +from pygmt.exceptions import GMTInvalidInput, GMTParameterError from pygmt.helpers import GMTTempFile from pygmt.helpers.testing import load_static_earth_relief @@ -101,5 +101,5 @@ def test_grdproject_fails(grid): """ Check that grdproject fails correctly. """ - with pytest.raises(GMTInvalidInput): + with pytest.raises(GMTParameterError): grdproject(grid=grid) diff --git a/pygmt/tests/test_histogram.py b/pygmt/tests/test_histogram.py index 3f1a78f04b0..cdf2ecbe814 100644 --- a/pygmt/tests/test_histogram.py +++ b/pygmt/tests/test_histogram.py @@ -5,7 +5,7 @@ import pandas as pd import pytest from pygmt import Figure -from pygmt.exceptions import GMTInvalidInput +from pygmt.exceptions import GMTParameterError @pytest.fixture(scope="module", name="data", params=[list, pd.Series]) @@ -40,7 +40,7 @@ def test_histogram_baroffset(data): Test passing bar_offset requires bar_width. """ fig = Figure() - with pytest.raises(GMTInvalidInput): + with pytest.raises(GMTParameterError): fig.histogram( data=data, projection="X10c/10c", diff --git a/pygmt/tests/test_inset.py b/pygmt/tests/test_inset.py index 63c99fe5d90..a5c219bf02a 100644 --- a/pygmt/tests/test_inset.py +++ b/pygmt/tests/test_inset.py @@ -4,7 +4,7 @@ import pytest from pygmt import Figure -from pygmt.exceptions import GMTInvalidInput +from pygmt.exceptions import GMTInvalidInput, GMTParameterError from pygmt.params import Box, Position @@ -86,11 +86,11 @@ def test_inset_invalid_inputs(): fig = Figure() fig.basemap(region="MG+r2", frame="afg") # Width is not given - with pytest.raises(GMTInvalidInput): + with pytest.raises(GMTParameterError): with fig.inset(position=Position("TL")): pass # Height is given but width is not given - with pytest.raises(GMTInvalidInput): + with pytest.raises(GMTParameterError): with fig.inset(position=Position("TL"), height="5c"): pass # Old position syntax conflicts with width/height diff --git a/pygmt/tests/test_magnetic_rose.py b/pygmt/tests/test_magnetic_rose.py index 6102c1b0054..d6d5cf1bddf 100644 --- a/pygmt/tests/test_magnetic_rose.py +++ b/pygmt/tests/test_magnetic_rose.py @@ -4,7 +4,7 @@ import pytest from pygmt import Figure -from pygmt.exceptions import GMTInvalidInput +from pygmt.exceptions import GMTParameterError from pygmt.params import Position @@ -46,5 +46,5 @@ def test_magnetic_rose_invalid_declination_label(): """ fig = Figure() fig.basemap(region=[-10, 10, -10, 10], projection="M10c", frame=True) - with pytest.raises(GMTInvalidInput): + with pytest.raises(GMTParameterError): fig.magnetic_rose(declination_label="11.5°E") diff --git a/pygmt/tests/test_meca.py b/pygmt/tests/test_meca.py index 618b1cfbbed..2b1b41218f3 100644 --- a/pygmt/tests/test_meca.py +++ b/pygmt/tests/test_meca.py @@ -8,7 +8,7 @@ import pandas as pd import pytest from pygmt import Figure -from pygmt.exceptions import GMTInvalidInput, GMTValueError +from pygmt.exceptions import GMTParameterError, GMTValueError from pygmt.helpers import GMTTempFile @@ -283,7 +283,7 @@ def test_meca_spec_ndarray_no_convention(): """ fig = Figure() fig.basemap(region=[-125, -122, 47, 49], projection="M6c", frame=True) - with pytest.raises(GMTInvalidInput): + with pytest.raises(GMTParameterError): fig.meca(spec=np.array([[-124, 48, 12.0, 330, 30, 90, 3]]), scale="1c") diff --git a/pygmt/tests/test_project.py b/pygmt/tests/test_project.py index 36917368c63..cdf71a236f5 100644 --- a/pygmt/tests/test_project.py +++ b/pygmt/tests/test_project.py @@ -10,7 +10,7 @@ import pytest import xarray as xr from pygmt import project -from pygmt.exceptions import GMTInvalidInput +from pygmt.exceptions import GMTInvalidInput, GMTParameterError from pygmt.helpers import GMTTempFile @@ -81,10 +81,10 @@ def test_project_incorrect_parameters(): Run project by providing incorrect parameters such as 1) no `center`; 2) no `data` or `generate`; and 3) `generate` with `convention`. """ - with pytest.raises(GMTInvalidInput): + with pytest.raises(GMTParameterError): # No `center` project(azimuth=45) - with pytest.raises(GMTInvalidInput): + with pytest.raises(GMTParameterError): # No `data` or `generate` project(center=[0, -1], azimuth=45, flat_earth=True) with pytest.raises(GMTInvalidInput): diff --git a/pygmt/tests/test_sphdistance.py b/pygmt/tests/test_sphdistance.py index f96f14530e5..a4ad9fb2cdf 100644 --- a/pygmt/tests/test_sphdistance.py +++ b/pygmt/tests/test_sphdistance.py @@ -9,7 +9,7 @@ import pytest from pygmt import sphdistance from pygmt.enums import GridRegistration, GridType -from pygmt.exceptions import GMTInvalidInput +from pygmt.exceptions import GMTParameterError from pygmt.helpers import GMTTempFile @@ -69,5 +69,5 @@ def test_sphdistance_fails(array): """ Check that sphdistance fails correctly when neither increment nor region is given. """ - with pytest.raises(GMTInvalidInput): + with pytest.raises(GMTParameterError): sphdistance(data=array) diff --git a/pygmt/tests/test_text.py b/pygmt/tests/test_text.py index 931f1a18554..a3fcdf05b0f 100644 --- a/pygmt/tests/test_text.py +++ b/pygmt/tests/test_text.py @@ -90,7 +90,7 @@ def test_text_without_text_input(region, projection): Run text by passing in x and y, but no text. """ fig = Figure() - with pytest.raises(GMTInvalidInput): + with pytest.raises(GMTParameterError): fig.text(region=region, projection=projection, x=1.2, y=2.4) diff --git a/pygmt/tests/test_velo.py b/pygmt/tests/test_velo.py index de2cb20e50c..0b264bfbc9e 100644 --- a/pygmt/tests/test_velo.py +++ b/pygmt/tests/test_velo.py @@ -5,7 +5,7 @@ import pandas as pd import pytest from pygmt import Figure -from pygmt.exceptions import GMTInvalidInput, GMTTypeError +from pygmt.exceptions import GMTParameterError, GMTTypeError @pytest.fixture(scope="module", name="dataframe") @@ -60,7 +60,7 @@ def test_velo_without_spec(dataframe): Check that velo fails when the spec parameter is not given. """ fig = Figure() - with pytest.raises(GMTInvalidInput): + with pytest.raises(GMTParameterError): fig.velo(data=dataframe) diff --git a/pygmt/tests/test_xyz2grd.py b/pygmt/tests/test_xyz2grd.py index 9f70c73cf8c..bf7fe854233 100644 --- a/pygmt/tests/test_xyz2grd.py +++ b/pygmt/tests/test_xyz2grd.py @@ -10,7 +10,7 @@ from pygmt import xyz2grd from pygmt.datasets import load_sample_data from pygmt.enums import GridRegistration, GridType -from pygmt.exceptions import GMTInvalidInput +from pygmt.exceptions import GMTParameterError from pygmt.helpers import GMTTempFile @@ -75,9 +75,9 @@ def test_xyz2grd_missing_region_spacing(ship_data): """ Test xyz2grd raise an exception if region or spacing is missing. """ - with pytest.raises(GMTInvalidInput): + with pytest.raises(GMTParameterError): xyz2grd(data=ship_data) - with pytest.raises(GMTInvalidInput): + with pytest.raises(GMTParameterError): xyz2grd(data=ship_data, region=[245, 255, 20, 30]) - with pytest.raises(GMTInvalidInput): + with pytest.raises(GMTParameterError): xyz2grd(data=ship_data, spacing=5)