(use_dask: bool)
| 510 | @requires_scipy |
| 511 | @pytest.mark.parametrize("use_dask", [True, False]) |
| 512 | def 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 |
nothing calls this directly
no test coverage detected
searching dependent graphs…