()
| 201 | |
| 202 | |
| 203 | def test_coordinate_transform_sel() -> None: |
| 204 | ds = create_coords(scale=2.0, shape=(4, 4)).to_dataset() |
| 205 | |
| 206 | data = [ |
| 207 | [0.0, 1.0, 2.0, 3.0], |
| 208 | [4.0, 5.0, 6.0, 7.0], |
| 209 | [8.0, 9.0, 10.0, 11.0], |
| 210 | [12.0, 13.0, 14.0, 15.0], |
| 211 | ] |
| 212 | ds["data"] = (("y", "x"), data) |
| 213 | |
| 214 | actual = ds.sel( |
| 215 | x=xr.Variable("z", [0.5, 5.5]), y=xr.Variable("z", [0.0, 0.5]), method="nearest" |
| 216 | ) |
| 217 | expected = ds.isel(x=xr.Variable("z", [0, 3]), y=xr.Variable("z", [0, 0])) |
| 218 | |
| 219 | # cannot use `assert_equal()` test utility function here yet |
| 220 | # (indexes invariant check are still based on IndexVariable, which |
| 221 | # doesn't work with coordinate transform index coordinate variables) |
| 222 | assert actual.equals(expected) |
| 223 | |
| 224 | with pytest.raises(ValueError, match=r".*only supports selection.*nearest"): |
| 225 | ds.sel(x=xr.Variable("z", [0.5, 5.5]), y=xr.Variable("z", [0.0, 0.5])) |
| 226 | |
| 227 | with pytest.raises(ValueError, match=r"missing labels for coordinate.*y"): |
| 228 | ds.sel(x=[0.5, 5.5], method="nearest") |
| 229 | |
| 230 | with pytest.raises(TypeError, match=r".*only supports advanced.*indexing"): |
| 231 | ds.sel(x=[0.5, 5.5], y=[0.0, 0.5], method="nearest") |
| 232 | |
| 233 | with pytest.raises(ValueError, match=r".*only supports advanced.*indexing"): |
| 234 | ds.sel( |
| 235 | x=xr.Variable("z", [0.5, 5.5]), |
| 236 | y=xr.Variable("z", [0.0, 0.5, 1.5]), |
| 237 | method="nearest", |
| 238 | ) |
| 239 | |
| 240 | |
| 241 | def test_coordinate_transform_rename() -> None: |
nothing calls this directly
no test coverage detected
searching dependent graphs…