Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
initial test
  • Loading branch information
TomNicholas committed Sep 6, 2025
commit c03b0e94a70e8555b3e41df1c84e89c261bf90cd
21 changes: 21 additions & 0 deletions xarray/tests/test_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -2175,6 +2175,27 @@ def test_sel_method(self) -> None:
with pytest.raises(ValueError, match=r"cannot supply"):
data.sel(dim1=0, method="nearest")

def test_sel_method_with_slice(self) -> None:
# regression test for https://github.com/pydata/xarray/issues/10710

data_int_coords = xr.Dataset(coords={"lat": ("lat", [20, 21, 22, 23])})
expected = xr.Dataset(coords={"lat": ("lat", [21, 22])})
actual = data_int_coords.sel(lat=slice(21, 22), method="nearest")
assert_identical(expected, actual)

# check consistency with not passing method kwarg, for case of ints, where method kwarg should be irrelevant
expected = data_int_coords.sel(lat=slice(21, 22))
assert_identical(expected, actual)

data_float_coords = xr.Dataset(
coords={"lat": ("lat", [20.1, 21.1, 22.1, 23.1])}
)
expected = xr.Dataset(coords={"lat": ("lat", [21.1, 22.1])})
actual = data_float_coords.sel(lat=slice(21, 22), method="nearest")
assert_identical(expected, actual)

# TODO backwards slices?

def test_loc(self) -> None:
data = create_test_data()
expected = data.sel(dim3="a")
Expand Down