Skip to content

Commit

Permalink
nd_nd test update
Browse files Browse the repository at this point in the history
  • Loading branch information
hollymandel committed Oct 25, 2024
1 parent 5318d0c commit bde9923
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions xarray/tests/test_interp.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,22 +407,27 @@ def test_interpolate_nd_inseparable(


@requires_scipy
@pytest.mark.parametrize("method", ("linear", "nearest", "quintic"))
@pytest.mark.parametrize("method", ("linear", "nearest"))
def test_interpolate_nd_nd(method: InterpnOptions) -> None:
"""Interpolate nd array with an nd indexer sharing coordinates."""
# Create original array
a = [0, 2]
x = [0, 1, 2]
da = xr.DataArray(
np.arange(6).reshape(2, 3), dims=("a", "x"), coords={"a": a, "x": x}
)
values = np.arange(6).reshape(2, 3)
da = xr.DataArray(values, dims=("a", "x"), coords={"a": a, "x": x})

# Create indexer into `a` with dimensions (y, x)
y = [10]
a_targets = [1, 2, 2]
c = {"x": x, "y": y}
ia = xr.DataArray([[1, 2, 2]], dims=("y", "x"), coords=c)
out = da.interp(a=ia)
expected = xr.DataArray([[1.5, 4, 5]], dims=("y", "x"), coords=c)
ia = xr.DataArray([a_targets], dims=("y", "x"), coords=c)
out = da.interp(a=ia, method=method)

expected_xi = list(zip(a_targets, x, strict=False))
expected_vec = scipy.interpolate.interpn(
points=(a, x), values=values, xi=expected_xi, method=method
)
expected = xr.DataArray([expected_vec], dims=("y", "x"), coords=c)
xr.testing.assert_allclose(out.drop_vars("a"), expected)

# If the *shared* indexing coordinates do not match, interp should fail.
Expand Down

0 comments on commit bde9923

Please sign in to comment.