MCPcopy
hub / github.com/pydata/xarray / test_tree_index_1d_coords

Function test_tree_index_1d_coords

xarray/tests/test_nd_point_index.py:196–223  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

194
195@requires_scipy
196def test_tree_index_1d_coords() -> None:
197 ds = xr.Dataset(
198 {"temp": ("points", np.arange(20, dtype=float))},
199 coords={
200 "x": ("points", np.linspace(0, 10, 20)),
201 "y": ("points", np.linspace(15, 8, 20)),
202 },
203 )
204 ds_indexed = ds.set_xindex(("x", "y"), NDPointIndex)
205
206 assert isinstance(ds_indexed.xindexes["x"], NDPointIndex)
207
208 actual = ds_indexed.sel(x=5.0, y=11.5, method="nearest")
209 assert actual.temp.values == 10.0
210
211 actual = ds_indexed.sel(
212 x=xr.Variable("query", [0.0, 5.0, 10.0]),
213 y=xr.Variable("query", [15.0, 11.5, 8.0]),
214 method="nearest",
215 )
216 expected = xr.Dataset(
217 {"temp": ("query", [0.0, 10.0, 19.0])},
218 coords={
219 "x": ("query", [0.0, ds.x.values[10], 10.0]),
220 "y": ("query", [15.0, ds.y.values[10], 8.0]),
221 },
222 )
223 assert_identical(actual, expected)

Callers

nothing calls this directly

Calls 5

set_xindexMethod · 0.95
assert_identicalFunction · 0.90
arangeMethod · 0.80
linspaceMethod · 0.80
selMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…