Skip to content

Commit 45a826b

Browse files
committed
Add test for #8909
Closes #8909, #8921
1 parent 18f913c commit 45a826b

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

xarray/tests/test_backends.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1427,6 +1427,25 @@ def test_string_object_warning(self) -> None:
14271427
with self.roundtrip(original) as actual:
14281428
assert_identical(original, actual)
14291429

1430+
@pytest.mark.parametrize(
1431+
"indexer",
1432+
(
1433+
{"y": [1]},
1434+
{"y": slice(2)},
1435+
{"y": 1},
1436+
{"x": [1], "y": [1]},
1437+
{"x": ("x0", [0, 1]), "y": ("x0", [0, 1])},
1438+
),
1439+
)
1440+
def test_indexing_roundtrip(self, indexer) -> None:
1441+
# regression test for GH8909
1442+
ds = xr.Dataset()
1443+
ds["A"] = xr.DataArray([[1, "a"], [2, "b"]], dims=["x", "y"])
1444+
with self.roundtrip(ds) as ds2:
1445+
expected = ds2.sel(indexer)
1446+
with self.roundtrip(expected) as actual:
1447+
assert_identical(actual, expected)
1448+
14301449

14311450
class NetCDFBase(CFEncodedBase):
14321451
"""Tests for all netCDF3 and netCDF4 backends."""

0 commit comments

Comments
 (0)