Skip to content

Commit 3349396

Browse files
committed
Merge two tests using pytest parametrize
Check that numpy.array and xarray.Dataset inputs work.
1 parent a0da121 commit 3349396

File tree

1 file changed

+7
-20
lines changed

1 file changed

+7
-20
lines changed

pygmt/tests/test_nearneighbor.py

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"""
44
import os
55

6+
import numpy as np
67
import numpy.testing as npt
78
import pytest
89
import xarray as xr
@@ -20,32 +21,18 @@ def fixture_ship_data():
2021
return load_sample_bathymetry()
2122

2223

23-
def test_nearneighbor_input_file():
24+
@pytest.mark.parametrize("array_func", [np.array, xr.Dataset])
25+
def test_nearneighbor_input_data(array_func, ship_data):
2426
"""
25-
Run nearneighbor by passing in a filename.
27+
Run nearneighbor by passing in a numpy.array or xarray.Dataset.
2628
"""
27-
output = nearneighbor(
28-
data="@tut_ship.xyz",
29-
spacing="5m",
30-
region=[245, 255, 20, 30],
31-
search_radius="10m",
32-
)
33-
assert isinstance(output, xr.DataArray)
34-
assert output.gmt.registration == 0 # Gridline registration
35-
assert output.gmt.gtype == 0 # Cartesian type
36-
assert output.shape == (121, 121)
37-
npt.assert_allclose(output.mean(), -2378.2385)
38-
39-
40-
def test_nearneighbor_input_numpy_array(ship_data):
41-
"""
42-
Run nearneighbor by passing in a numpy array into data.
43-
"""
44-
data = ship_data.values # convert pandas.DataFrame to numpy.ndarray
29+
data = array_func(ship_data)
4530
output = nearneighbor(
4631
data=data, spacing="5m", region=[245, 255, 20, 30], search_radius="10m"
4732
)
4833
assert isinstance(output, xr.DataArray)
34+
assert output.gmt.registration == 0 # Gridline registration
35+
assert output.gmt.gtype == 1 # Geographic type
4936
assert output.shape == (121, 121)
5037
npt.assert_allclose(output.mean(), -2378.2385)
5138

0 commit comments

Comments
 (0)