Skip to content

Commit 926e7ce

Browse files
tomwhitemergify[bot]
authored andcommitted
Fix test for more restrictive xarray multi-index
1 parent e0b3669 commit 926e7ce

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

sgkit/tests/test_variables.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,12 @@ def test_variables__variables_registered():
1616

1717
@pytest.fixture()
1818
def dummy_ds():
19-
# foo is a data variable, bar is a coordinate
19+
# foo ans baz are data variables, bar is a coordinate
2020
return xr.Dataset(
2121
{
2222
"foo": ("d1", np.asarray([1, 2, 3])),
2323
"bar": np.asarray([1, 2, 3]),
24+
"baz": ("d1", np.asarray([4, 5, 6])),
2425
}
2526
)
2627

@@ -82,20 +83,24 @@ def test_variables__multiple_specs(dummy_ds: xr.Dataset) -> None:
8283
def test_variables__whole_ds(dummy_ds: xr.Dataset) -> None:
8384
spec_foo = ArrayLikeSpec("foo", "foo doc", kind="i", ndim=1)
8485
spec_bar = ArrayLikeSpec("bar", "bar doc", kind="i", ndim=1)
86+
spec_baz = ArrayLikeSpec("baz", "baz doc", kind="i", ndim=1)
8587
try:
8688
SgkitVariables.register_variable(spec_foo)
8789
with pytest.raises(ValueError, match="`foo` already registered"):
8890
SgkitVariables.register_variable(spec_foo)
8991
SgkitVariables.register_variable(spec_bar)
92+
SgkitVariables.register_variable(spec_baz)
9093
variables.validate(dummy_ds)
9194
finally:
9295
SgkitVariables.registered_variables.pop("foo", None)
9396
SgkitVariables.registered_variables.pop("bar", None)
97+
SgkitVariables.registered_variables.pop("baz", None)
9498

9599

96100
def test_variables_in_multi_index(dummy_ds: xr.Dataset) -> None:
97101
# create a multi index
98-
ds = dummy_ds.set_index({"ind": ("foo", "bar")})
102+
# variables must share a dimension since https://github.com/pydata/xarray/pull/5692
103+
ds = dummy_ds.set_index({"ind": ("foo", "baz")})
99104

100105
spec = ArrayLikeSpec("foo", "foo doc", kind="i", ndim=1)
101106
variables.validate(ds, spec)

0 commit comments

Comments
 (0)