-
Notifications
You must be signed in to change notification settings - Fork 235
BREAKING: Raise GMTParameterError exception for conflicts_with parameters. Previously raise GMTInvalidInput #4387
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
0105bb6
d8c15e7
7b6d102
406eb7b
b28747d
c15f3f3
25bad04
7d9bd89
fc029ad
47f3e1e
11991fe
3fef364
350f67d
e4f040f
f73fcdb
1ed8e05
5a5b87d
a096843
5cbcbe3
af21ef2
ce3c9cc
3c94d17
7c454ba
355ba29
c260d4a
b3c4ba5
368a102
35ebe3c
e8380d4
fdeba84
0deddd2
6e951b3
c3bf105
28e0582
e33a11a
3743e11
f2194bf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -145,6 +145,9 @@ class GMTParameterError(GMTError): | |||||
| at_most_one | ||||||
| A set of mutually exclusive parameter names, of which at most one can be | ||||||
| specified. | ||||||
| conflicts_with | ||||||
| A tuple with the parameter name and a set of conflicting parameter names, | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| indicating which parameters cannot be used together. | ||||||
| reason | ||||||
| Detailed reason why the parameters are invalid. | ||||||
| """ | ||||||
|
|
@@ -155,6 +158,7 @@ def __init__( | |||||
| required: str | set[str] | None = None, | ||||||
| at_least_one: set[str] | None = None, | ||||||
| at_most_one: set[str] | None = None, | ||||||
| conflicts_with: tuple[str, set[str]] | None = None, | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| reason: str | None = None, | ||||||
| ): | ||||||
| msg = [] | ||||||
|
|
@@ -177,6 +181,12 @@ def __init__( | |||||
| f"{', '.join(repr(par) for par in at_most_one)}. " | ||||||
| "Specify at most one of them." | ||||||
| ) | ||||||
| if conflicts_with: | ||||||
| param, conflicts = conflicts_with | ||||||
| msg.append( | ||||||
| f"Conflicting parameters: {param!r} cannot be used with " | ||||||
| f"{', '.join(repr(c) for c in conflicts)}." | ||||||
| ) | ||||||
| if reason: | ||||||
| msg.append(reason) | ||||||
| super().__init__(" ".join(msg)) | ||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -7,7 +7,7 @@ | |||||
| from pathlib import Path | ||||||
| from typing import Any, ClassVar, Literal | ||||||
|
|
||||||
| from pygmt.exceptions import GMTInvalidInput, GMTTypeError, GMTValueError | ||||||
| from pygmt.exceptions import GMTParameterError, GMTTypeError, GMTValueError | ||||||
| from pygmt.params.position import Position | ||||||
| from pygmt.src.which import which | ||||||
|
|
||||||
|
|
@@ -328,7 +328,7 @@ def _parse_position( | |||||
| ... ) | ||||||
| Traceback (most recent call last): | ||||||
| ... | ||||||
| pygmt.exceptions.GMTInvalidInput: Parameter 'position' is given with a raw GMT... | ||||||
| pygmt.exceptions.GMTParameterError: ... | ||||||
|
|
||||||
| >>> _parse_position( | ||||||
| ... 123, | ||||||
|
|
@@ -364,12 +364,10 @@ def _parse_position( | |||||
| position = Position(position, cstype="inside") | ||||||
| elif kwdict is not None: # Raw GMT command string with potential conflicts. | ||||||
| if any(v is not None and v is not False for v in kwdict.values()): | ||||||
| msg = ( | ||||||
| "Parameter 'position' is given with a raw GMT command string, " | ||||||
| "and conflicts with parameters " | ||||||
| f"{', '.join(repr(c) for c in kwdict)}." | ||||||
| raise GMTParameterError( | ||||||
| conflicts_with=("position", set(kwdict)), | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| reason="'position' is specified using the unrecommended GMT command string syntax.", | ||||||
| ) | ||||||
| raise GMTInvalidInput(msg) | ||||||
| else: | ||||||
| # No conflicting parameters to check, indicating it's a new function. | ||||||
| # The string must be an anchor code. | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -10,7 +10,7 @@ | |||||
| from pygmt._typing import PathLike | ||||||
| from pygmt.alias import Alias, AliasSystem | ||||||
| from pygmt.clib import Session, __gmt_version__ | ||||||
| from pygmt.exceptions import GMTInvalidInput | ||||||
| from pygmt.exceptions import GMTInvalidInput, GMTParameterError | ||||||
| from pygmt.helpers import build_arg_list, deprecate_parameter, fmt_docstring, use_alias | ||||||
| from pygmt.src.grdinfo import grdinfo | ||||||
|
|
||||||
|
|
@@ -71,11 +71,13 @@ def _alias_option_Q( # noqa: N802 | |||||
| v is not None and v is not False | ||||||
| for v in (dpi, mesh_fill, monochrome, nan_transparent) | ||||||
| ): | ||||||
| msg = ( | ||||||
| "Parameter 'surftype' is given with a raw GMT command string, and conflicts " | ||||||
| "with parameters 'dpi', 'mesh_fill', 'monochrome', or 'nan_transparent'." | ||||||
| raise GMTParameterError( | ||||||
| conflicts_with=( | ||||||
| "surftype", | ||||||
| {"dpi", "mesh_fill", "monochrome", "nan_transparent"}, | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| ), | ||||||
| reason="'surftype' is specified using the unrecommended GMT command string syntax.", | ||||||
| ) | ||||||
| raise GMTInvalidInput(msg) | ||||||
|
|
||||||
| if dpi is not None and surftype != "image": | ||||||
| msg = "Parameter 'dpi' can only be used when 'surftype' is 'image'." | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.