(self)
| 2086 | |
| 2087 | @pytest.mark.filterwarnings("ignore::FutureWarning") |
| 2088 | def test_sel_fancy(self) -> None: |
| 2089 | data = create_test_data() |
| 2090 | |
| 2091 | # add in a range() index |
| 2092 | data["dim1"] = data.dim1 |
| 2093 | |
| 2094 | pdim1 = [1, 2, 3] |
| 2095 | pdim2 = [4, 5, 1] |
| 2096 | pdim3 = [1, 2, 3] |
| 2097 | expected = data.isel( |
| 2098 | dim1=Variable(("test_coord",), pdim1), |
| 2099 | dim2=Variable(("test_coord",), pdim2), |
| 2100 | dim3=Variable(("test_coord"), pdim3), |
| 2101 | ) |
| 2102 | actual = data.sel( |
| 2103 | dim1=Variable(("test_coord",), data.dim1[pdim1]), |
| 2104 | dim2=Variable(("test_coord",), data.dim2[pdim2]), |
| 2105 | dim3=Variable(("test_coord",), data.dim3[pdim3]), |
| 2106 | ) |
| 2107 | assert_identical(expected, actual) |
| 2108 | |
| 2109 | # DataArray Indexer |
| 2110 | idx_t = DataArray( |
| 2111 | data["time"][[3, 2, 1]].values, dims=["a"], coords={"a": ["a", "b", "c"]} |
| 2112 | ) |
| 2113 | idx_2 = DataArray( |
| 2114 | data["dim2"][[3, 2, 1]].values, dims=["a"], coords={"a": ["a", "b", "c"]} |
| 2115 | ) |
| 2116 | idx_3 = DataArray( |
| 2117 | data["dim3"][[3, 2, 1]].values, dims=["a"], coords={"a": ["a", "b", "c"]} |
| 2118 | ) |
| 2119 | actual = data.sel(time=idx_t, dim2=idx_2, dim3=idx_3) |
| 2120 | expected = data.isel( |
| 2121 | time=Variable(("a",), [3, 2, 1]), |
| 2122 | dim2=Variable(("a",), [3, 2, 1]), |
| 2123 | dim3=Variable(("a",), [3, 2, 1]), |
| 2124 | ) |
| 2125 | expected = expected.assign_coords(a=idx_t["a"]) |
| 2126 | assert_identical(expected, actual) |
| 2127 | |
| 2128 | idx_t = DataArray( |
| 2129 | data["time"][[3, 2, 1]].values, dims=["a"], coords={"a": ["a", "b", "c"]} |
| 2130 | ) |
| 2131 | idx_2 = DataArray( |
| 2132 | data["dim2"][[2, 1, 3]].values, dims=["b"], coords={"b": [0, 1, 2]} |
| 2133 | ) |
| 2134 | idx_3 = DataArray( |
| 2135 | data["dim3"][[1, 2, 1]].values, dims=["c"], coords={"c": [0.0, 1.1, 2.2]} |
| 2136 | ) |
| 2137 | actual = data.sel(time=idx_t, dim2=idx_2, dim3=idx_3) |
| 2138 | expected = data.isel( |
| 2139 | time=Variable(("a",), [3, 2, 1]), |
| 2140 | dim2=Variable(("b",), [2, 1, 3]), |
| 2141 | dim3=Variable(("c",), [1, 2, 1]), |
| 2142 | ) |
| 2143 | expected = expected.assign_coords(a=idx_t["a"], b=idx_2["b"], c=idx_3["c"]) |
| 2144 | assert_identical(expected, actual) |
| 2145 |
nothing calls this directly
no test coverage detected