Skip to content

Commit a668235

Browse files
pygmt.grdproject: Raise an exception when both 'unit' and 'scaling' are given (#4371)
1 parent 3062417 commit a668235

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

pygmt/src/grdproject.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,10 @@ def grdproject( # noqa: PLR0913
120120
msg = "Parameter 'projection' must be specified."
121121
raise GMTInvalidInput(msg)
122122

123+
if kwargs.get("M", unit) is not None and kwargs.get("F", scaling) is not False:
124+
msg = "Cannot use both 'unit' and 'scaling'."
125+
raise GMTInvalidInput(msg)
126+
123127
aliasdict = AliasSystem(
124128
C=Alias(center, name="center", sep="/", size=2),
125129
D=Alias(spacing, name="spacing", sep="/", size=2),

pygmt/tests/test_grdproject.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,22 @@ def test_grdproject_no_outgrid(grid, projection, expected_grid):
8181
xr.testing.assert_allclose(a=result, b=expected_grid)
8282

8383

84+
def test_grdproject_unit_scaling(grid):
85+
"""
86+
Test that the input validation to prevent passing both 'unit' and
87+
'scaling' is performed.
88+
"""
89+
with pytest.raises(GMTInvalidInput):
90+
grdproject(
91+
grid=grid,
92+
projection="M10c",
93+
spacing=3,
94+
unit="i",
95+
scaling="k",
96+
region=[-53, -51, -20, -17],
97+
)
98+
99+
84100
def test_grdproject_fails(grid):
85101
"""
86102
Check that grdproject fails correctly.

0 commit comments

Comments
 (0)