MCPcopy Index your code
hub / github.com/pydata/xarray / test_sorted

Function test_sorted

xarray/tests/test_interp.py:564–587  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

562
563@requires_scipy
564def 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

Callers

nothing calls this directly

Calls 5

sortbyMethod · 0.95
interpMethod · 0.95
assert_allcloseFunction · 0.90
linspaceMethod · 0.80
interpMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…