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

Function test_interpolate_dimorder

xarray/tests/test_interp.py:630–674  ·  view source on GitHub ↗

Make sure the resultant dimension order is consistent with .sel()

(case: int)

Source from the content-addressed store, hash-verified

628
629@pytest.mark.parametrize("case", [pytest.param(0, id="2D"), pytest.param(3, id="3D")])
630def test_interpolate_dimorder(case: int) -> None:
631 """Make sure the resultant dimension order is consistent with .sel()"""
632 if not has_scipy:
633 pytest.skip("scipy is not installed.")
634
635 da = get_example_data(case)
636
637 new_x = xr.DataArray([0, 1, 2], dims="x")
638 assert da.interp(x=new_x).dims == da.sel(x=new_x, method="nearest").dims
639
640 new_y = xr.DataArray([0, 1, 2], dims="y")
641 actual = da.interp(x=new_x, y=new_y).dims
642 expected = da.sel(x=new_x, y=new_y, method="nearest").dims
643 assert actual == expected
644 # reversed order
645 actual = da.interp(y=new_y, x=new_x).dims
646 expected = da.sel(y=new_y, x=new_x, method="nearest").dims
647 assert actual == expected
648
649 new_x = xr.DataArray([0, 1, 2], dims="a")
650 assert da.interp(x=new_x).dims == da.sel(x=new_x, method="nearest").dims
651 assert da.interp(y=new_x).dims == da.sel(y=new_x, method="nearest").dims
652 new_y = xr.DataArray([0, 1, 2], dims="a")
653 actual = da.interp(x=new_x, y=new_y).dims
654 expected = da.sel(x=new_x, y=new_y, method="nearest").dims
655 assert actual == expected
656
657 new_x = xr.DataArray([[0], [1], [2]], dims=["a", "b"])
658 assert da.interp(x=new_x).dims == da.sel(x=new_x, method="nearest").dims
659 assert da.interp(y=new_x).dims == da.sel(y=new_x, method="nearest").dims
660
661 if case == 3:
662 new_x = xr.DataArray([[0], [1], [2]], dims=["a", "b"])
663 new_z = xr.DataArray([[0], [1], [2]], dims=["a", "b"])
664 actual = da.interp(x=new_x, z=new_z).dims
665 expected = da.sel(x=new_x, z=new_z, method="nearest").dims
666 assert actual == expected
667
668 actual = da.interp(z=new_z, x=new_x).dims
669 expected = da.sel(z=new_z, x=new_x, method="nearest").dims
670 assert actual == expected
671
672 actual = da.interp(x=0.5, z=new_z).dims
673 expected = da.sel(x=0.5, z=new_z, method="nearest").dims
674 assert actual == expected
675
676
677@requires_scipy

Callers

nothing calls this directly

Calls 3

get_example_dataFunction · 0.85
interpMethod · 0.45
selMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…