MCPcopy
hub / github.com/pydata/xarray / test_interpolate_1d

Function test_interpolate_1d

xarray/tests/test_interp.py:123–151  ·  view source on GitHub ↗
(method: InterpOptions, dim: str, case: int)

Source from the content-addressed store, hash-verified

121 "case", [pytest.param(0, id="no_chunk"), pytest.param(1, id="chunk_y")]
122)
123def test_interpolate_1d(method: InterpOptions, dim: str, case: int) -> None:
124 if not has_scipy:
125 pytest.skip("scipy is not installed.")
126
127 if not has_dask and case == 1:
128 pytest.skip("dask is not installed in the environment.")
129
130 da = get_example_data(case)
131 xdest = np.linspace(0.0, 0.9, 80)
132 actual = da.interp(method=method, coords={dim: xdest})
133
134 # scipy interpolation for the reference
135 def func(obj, new_x):
136 return scipy.interpolate.interp1d(
137 da[dim],
138 obj.data,
139 axis=obj.get_axis_num(dim),
140 bounds_error=False,
141 fill_value=np.nan,
142 kind=method, # type: ignore[arg-type,unused-ignore]
143 )(new_x)
144
145 if dim == "x":
146 coords = {"x": xdest, "y": da["y"], "x2": ("x", func(da["x2"], xdest))}
147 else: # y
148 coords = {"x": da["x"], "y": xdest, "x2": da["x2"]}
149
150 expected = xr.DataArray(func(da, xdest), dims=["x", "y"], coords=coords)
151 assert_allclose(actual, expected)
152
153
154@pytest.mark.parametrize("method", ["cubic", "zero"])

Callers

nothing calls this directly

Calls 5

assert_allcloseFunction · 0.90
get_example_dataFunction · 0.85
linspaceMethod · 0.80
funcFunction · 0.70
interpMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…