Add regression test for grdfill crash
@@ -6,11 +6,15 @@ import os
import numpy as np
import pytest
import xarray as xr
-from pygmt import grdfill, load_dataarray
+from packaging.version import Version
+from pygmt import clib, grdfill, load_dataarray
from pygmt.exceptions import GMTInvalidInput
from pygmt.helpers import GMTTempFile
from pygmt.helpers.testing import load_static_earth_relief
+with clib.Session() as _lib:
+ gmt_version = Version(_lib.info["version"])
+
@pytest.fixture(scope="module", name="grid")
def fixture_grid():
@@ -82,6 +86,28 @@ def test_grdfill_dataarray_out(grid, expected_grid):
xr.testing.assert_allclose(a=result, b=expected_grid)
+@pytest.mark.skipif(
+ gmt_version < Version("6.4.0"),
+ reason="Upstream bug/crash fixed in https://github.com/GenericMappingTools/gmt/pull/6418.",
+)
+def test_grdfill_asymmetric_pad(grid, expected_grid):
+ """
+ Test grdfill using a region that includes the edge of the grid.
+
+ Regression test for
+ https://github.com/GenericMappingTools/pygmt/issues/1745.
+ """
+ result = grdfill(grid=grid, mode="c20", region=[-55, -50, -24, -16])
+ # check information of the output grid
+ assert isinstance(result, xr.DataArray)
+ assert result.gmt.gtype == 1 # Geographic grid
+ assert result.gmt.registration == 1 # Pixel registration
+ # check information of the output grid
+ xr.testing.assert_allclose(
+ a=result, b=expected_grid.sel(lon=slice(-55, -50), lat=slice(-24, -16))
+ )
+
+
def test_grdfill_file_out(grid, expected_grid):
"""
Test grdfill with an outgrid set.
