(method: InterpOptions, dim: str, case: int)
| 121 | "case", [pytest.param(0, id="no_chunk"), pytest.param(1, id="chunk_y")] |
| 122 | ) |
| 123 | def 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"]) |
nothing calls this directly
no test coverage detected
searching dependent graphs…