MCPcopy Index your code
hub / github.com/pydata/xarray / test_interpolate_1d_methods

Function test_interpolate_1d_methods

xarray/tests/test_interp.py:155–178  ·  view source on GitHub ↗
(method: InterpOptions)

Source from the content-addressed store, hash-verified

153
154@pytest.mark.parametrize("method", ["cubic", "zero"])
155def test_interpolate_1d_methods(method: InterpOptions) -> None:
156 if not has_scipy:
157 pytest.skip("scipy is not installed.")
158
159 da = get_example_data(0)
160 dim = "x"
161 xdest = np.linspace(0.0, 0.9, 80)
162
163 actual = da.interp(method=method, coords={dim: xdest})
164
165 # scipy interpolation for the reference
166 def func(obj, new_x):
167 return scipy.interpolate.interp1d(
168 da[dim],
169 obj.data,
170 axis=obj.get_axis_num(dim),
171 bounds_error=False,
172 fill_value=np.nan,
173 kind=method, # type: ignore[arg-type,unused-ignore]
174 )(new_x)
175
176 coords = {"x": xdest, "y": da["y"], "x2": ("x", func(da["x2"], xdest))}
177 expected = xr.DataArray(func(da, xdest), dims=["x", "y"], coords=coords)
178 assert_allclose(actual, expected)
179
180
181@requires_scipy

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…