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

Function test_errors

xarray/tests/test_interp.py:512–543  ·  view source on GitHub ↗
(use_dask: bool)

Source from the content-addressed store, hash-verified

510@requires_scipy
511@pytest.mark.parametrize("use_dask", [True, False])
512def test_errors(use_dask: bool) -> None:
513 # spline is unavailable
514 da = xr.DataArray([0, 1, np.nan, 2], dims="x", coords={"x": range(4)})
515 if not has_dask and use_dask:
516 pytest.skip("dask is not installed in the environment.")
517 da = da.chunk()
518
519 for method in ["spline"]:
520 with pytest.raises(ValueError), pytest.warns(PendingDeprecationWarning):
521 da.interp(x=[0.5, 1.5], method=method) # type: ignore[arg-type]
522
523 # not sorted
524 if use_dask:
525 da = get_example_data(3)
526 else:
527 da = get_example_data(0)
528
529 result = da.interp(x=[-1, 1, 3], kwargs={"fill_value": 0.0})
530 assert not np.isnan(result.values).any()
531 result = da.interp(x=[-1, 1, 3])
532 assert np.isnan(result.values).any()
533
534 # invalid method
535 with pytest.raises(ValueError):
536 da.interp(x=[2, 0], method="boo") # type: ignore[arg-type]
537 with pytest.raises(ValueError):
538 da.interp(y=[2, 0], method="boo") # type: ignore[arg-type]
539
540 # object-type DataArray cannot be interpolated
541 da = xr.DataArray(["a", "b", "c"], dims="x", coords={"x": [0, 1, 2]})
542 with pytest.raises(TypeError):
543 da.interp(x=0)
544
545
546@requires_scipy

Callers

nothing calls this directly

Calls 4

chunkMethod · 0.95
interpMethod · 0.95
get_example_dataFunction · 0.85
anyMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…