(use_dask: bool, method: InterpOptions)
| 202 | ), |
| 203 | ) |
| 204 | def test_interpolate_vectorize(use_dask: bool, method: InterpOptions) -> None: |
| 205 | # scipy interpolation for the reference |
| 206 | def func(obj, dim, new_x, method): |
| 207 | scipy_kwargs = {} |
| 208 | interpolant_options = { |
| 209 | "barycentric": scipy.interpolate.BarycentricInterpolator, |
| 210 | "krogh": scipy.interpolate.KroghInterpolator, |
| 211 | "pchip": scipy.interpolate.PchipInterpolator, |
| 212 | "akima": scipy.interpolate.Akima1DInterpolator, |
| 213 | "makima": scipy.interpolate.Akima1DInterpolator, |
| 214 | } |
| 215 | |
| 216 | shape = [s for i, s in enumerate(obj.shape) if i != obj.get_axis_num(dim)] |
| 217 | for s in new_x.shape[::-1]: |
| 218 | shape.insert(obj.get_axis_num(dim), s) |
| 219 | |
| 220 | if method in interpolant_options: |
| 221 | interpolant = interpolant_options[method] |
| 222 | if method == "makima": |
| 223 | scipy_kwargs["method"] = method |
| 224 | return interpolant( |
| 225 | da[dim], obj.data, axis=obj.get_axis_num(dim), **scipy_kwargs |
| 226 | )(new_x).reshape(shape) |
| 227 | else: |
| 228 | return scipy.interpolate.interp1d( |
| 229 | da[dim], |
| 230 | obj.data, |
| 231 | axis=obj.get_axis_num(dim), |
| 232 | kind=method, # type: ignore[arg-type,unused-ignore] |
| 233 | bounds_error=False, |
| 234 | fill_value=np.nan, |
| 235 | **scipy_kwargs, |
| 236 | )(new_x).reshape(shape) |
| 237 | |
| 238 | da = get_example_data(0) |
| 239 | |
| 240 | if use_dask: |
| 241 | da = da.chunk({"y": 5}) |
| 242 | |
| 243 | # xdest is 1d but has different dimension |
| 244 | xdest = xr.DataArray( |
| 245 | np.linspace(0.1, 0.9, 30), |
| 246 | dims="z", |
| 247 | coords={"z": np.random.randn(30), "z2": ("z", np.random.randn(30))}, |
| 248 | ) |
| 249 | |
| 250 | actual = da.interp(x=xdest, method=method) |
| 251 | |
| 252 | expected = xr.DataArray( |
| 253 | func(da, "x", xdest, method), |
| 254 | dims=["z", "y"], |
| 255 | coords={ |
| 256 | "z": xdest["z"], |
| 257 | "z2": xdest["z2"], |
| 258 | "y": da["y"], |
| 259 | "x": ("z", xdest.values), |
| 260 | "x2": ("z", func(da["x2"], "x", xdest, method)), |
| 261 | }, |
nothing calls this directly
no test coverage detected
searching dependent graphs…