()
| 562 | |
| 563 | @requires_scipy |
| 564 | def test_sorted() -> None: |
| 565 | # unsorted non-uniform gridded data |
| 566 | x = np.random.randn(100) |
| 567 | y = np.random.randn(30) |
| 568 | z = np.linspace(0.1, 0.2, 10) * 3.0 |
| 569 | da = xr.DataArray( |
| 570 | np.cos(x[:, np.newaxis, np.newaxis]) * np.cos(y[:, np.newaxis]) * z, |
| 571 | dims=["x", "y", "z"], |
| 572 | coords={"x": x, "y": y, "x2": ("x", x**2), "z": z}, |
| 573 | ) |
| 574 | |
| 575 | x_new = np.linspace(0, 1, 30) |
| 576 | y_new = np.linspace(0, 1, 20) |
| 577 | |
| 578 | da_sorted = da.sortby("x") |
| 579 | assert_allclose(da.interp(x=x_new), da_sorted.interp(x=x_new, assume_sorted=True)) |
| 580 | da_sorted = da.sortby(["x", "y"]) |
| 581 | assert_allclose( |
| 582 | da.interp(x=x_new, y=y_new), |
| 583 | da_sorted.interp(x=x_new, y=y_new, assume_sorted=True), |
| 584 | ) |
| 585 | |
| 586 | with pytest.raises(ValueError): |
| 587 | da.interp(x=[0, 1, 2], assume_sorted=True) |
| 588 | |
| 589 | |
| 590 | @requires_scipy |
nothing calls this directly
no test coverage detected
searching dependent graphs…