Skip to content

Commit 8882f0a

Browse files
author
Meghan Jones
authored
Add regression test for grdfill crash (#1842)
1 parent 86e8640 commit 8882f0a

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

pygmt/tests/test_grdfill.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,15 @@
66
import numpy as np
77
import pytest
88
import xarray as xr
9-
from pygmt import grdfill, load_dataarray
9+
from packaging.version import Version
10+
from pygmt import clib, grdfill, load_dataarray
1011
from pygmt.exceptions import GMTInvalidInput
1112
from pygmt.helpers import GMTTempFile
1213
from pygmt.helpers.testing import load_static_earth_relief
1314

15+
with clib.Session() as _lib:
16+
gmt_version = Version(_lib.info["version"])
17+
1418

1519
@pytest.fixture(scope="module", name="grid")
1620
def fixture_grid():
@@ -82,6 +86,28 @@ def test_grdfill_dataarray_out(grid, expected_grid):
8286
xr.testing.assert_allclose(a=result, b=expected_grid)
8387

8488

89+
@pytest.mark.skipif(
90+
gmt_version < Version("6.4.0"),
91+
reason="Upstream bug/crash fixed in https://github.com/GenericMappingTools/gmt/pull/6418.",
92+
)
93+
def test_grdfill_asymmetric_pad(grid, expected_grid):
94+
"""
95+
Test grdfill using a region that includes the edge of the grid.
96+
97+
Regression test for
98+
https://github.com/GenericMappingTools/pygmt/issues/1745.
99+
"""
100+
result = grdfill(grid=grid, mode="c20", region=[-55, -50, -24, -16])
101+
# check information of the output grid
102+
assert isinstance(result, xr.DataArray)
103+
assert result.gmt.gtype == 1 # Geographic grid
104+
assert result.gmt.registration == 1 # Pixel registration
105+
# check information of the output grid
106+
xr.testing.assert_allclose(
107+
a=result, b=expected_grid.sel(lon=slice(-55, -50), lat=slice(-24, -16))
108+
)
109+
110+
85111
def test_grdfill_file_out(grid, expected_grid):
86112
"""
87113
Test grdfill with an outgrid set.

0 commit comments

Comments
 (0)