Skip to content

Commit 05a3a08

Browse files
committed
Ensure triangulate.delaunay_triples output_type is valid
Must be either one of numpy, pandas or file
1 parent 4db6812 commit 05a3a08

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

pygmt/src/triangulate.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"""
55
import pandas as pd
66
from pygmt.clib import Session
7+
from pygmt.exceptions import GMTInvalidInput
78
from pygmt.helpers import (
89
GMTTempFile,
910
build_arg_string,
@@ -337,6 +338,12 @@ def delaunay_triples( # pylint: disable=too-many-arguments,too-many-locals
337338
- None if ``outfile`` is a str (file output is stored in
338339
``outfile``)
339340
"""
341+
# Return a pandas.DataFrame if ``outfile`` is not set
342+
if output_type not in ["numpy", "pandas", "file"]:
343+
raise GMTInvalidInput(
344+
"Must specify 'output_type' either as 'numpy', 'pandas' or 'file'."
345+
)
346+
340347
# Return a pandas.DataFrame if ``outfile`` is not set
341348
with GMTTempFile(suffix=".txt") as tmpfile:
342349
if output_type != "file":

pygmt/tests/test_triangulate.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,14 @@ def test_delaunay_triples_ndarray_output(dataframe, expected_dataframe):
107107
np.testing.assert_allclose(actual=output, desired=expected_dataframe.to_numpy())
108108

109109

110+
def test_delaunay_triples_invalid_format(dataframe):
111+
"""
112+
Test that triangulate.delaunay_triples fails with incorrect format.
113+
"""
114+
with pytest.raises(GMTInvalidInput):
115+
triangulate.delaunay_triples(data=dataframe, output_type=1)
116+
117+
110118
def test_regular_grid_with_outgrid_true(dataframe, expected_grid):
111119
"""
112120
Run triangulate.regular_grid with outgrid=True and see it load into an

0 commit comments

Comments
 (0)