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

Function test_interpolate_scalar

xarray/tests/test_interp.py:435–457  ·  view source on GitHub ↗
(method: InterpOptions, case: int)

Source from the content-addressed store, hash-verified

433 "case", [pytest.param(0, id="no_chunk"), pytest.param(1, id="chunk_y")]
434)
435def test_interpolate_scalar(method: InterpOptions, case: int) -> None:
436 if not has_dask and case == 1:
437 pytest.skip("dask is not installed in the environment.")
438
439 da = get_example_data(case)
440 xdest = 0.4
441
442 actual = da.interp(x=xdest, method=method)
443
444 # scipy interpolation for the reference
445 def func(obj, new_x):
446 return scipy.interpolate.interp1d(
447 da["x"],
448 obj.data,
449 axis=obj.get_axis_num("x"),
450 bounds_error=False,
451 fill_value=np.nan,
452 kind=method, # type: ignore[arg-type,unused-ignore]
453 )(new_x)
454
455 coords = {"x": xdest, "y": da["y"], "x2": func(da["x2"], xdest)}
456 expected = xr.DataArray(func(da, xdest), dims=["y"], coords=coords)
457 assert_allclose(actual, expected)
458
459
460@requires_scipy

Callers

nothing calls this directly

Calls 4

assert_allcloseFunction · 0.90
get_example_dataFunction · 0.85
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…