(method: InterpOptions)
| 153 | |
| 154 | @pytest.mark.parametrize("method", ["cubic", "zero"]) |
| 155 | def 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 |
nothing calls this directly
no test coverage detected
searching dependent graphs…