Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions pygmt/src/contour.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from pygmt._typing import PathLike, TableLike
from pygmt.alias import Alias, AliasSystem
from pygmt.clib import Session
from pygmt.exceptions import GMTParameterError
from pygmt.helpers import (
build_arg_list,
fmt_docstring,
Expand Down Expand Up @@ -151,6 +152,9 @@ def contour(
$perspective
$transparency
"""
# Validate that 'data' and 'x,y,z' aren't both passed to contour
if data is not None and any(triplet is not None for triplet in (x, y, z)):
raise GMTParameterError(at_most_one=["data", "x/y/z"])
# Specify levels for contours or annotations.
# One level is converted to a string with a trailing comma to separate it from
# specifying an interval.
Expand Down
20 changes: 20 additions & 0 deletions pygmt/tests/test_contour.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import pytest
import xarray as xr
from pygmt import Figure
from pygmt.exceptions import GMTParameterError
from pygmt.params import Axis

POINTS_DATA = Path(__file__).parent / "data" / "points.txt"
Expand Down Expand Up @@ -198,3 +199,22 @@ def test_contour_incols_transposed_data(region):
incols=[1, 0, 2],
)
return fig


def test_contour_fail_too_much_data(data, region):
"""
Check that contour raises an exception if both data and x/y/z are given.
"""
fig = Figure()
with pytest.raises(GMTParameterError):
fig.contour(
data=data,
# Transpose x and y values
x=data[1],
y=data[0],
z=data[2],
region=region,
projection="X10c",
frame=Axis(annot=True),
pen=True,
)
Loading