@@ -16,11 +16,12 @@ def test_variables__variables_registered():
16
16
17
17
@pytest .fixture ()
18
18
def dummy_ds ():
19
- # foo is a data variable , bar is a coordinate
19
+ # foo ans baz are data variables , bar is a coordinate
20
20
return xr .Dataset (
21
21
{
22
22
"foo" : ("d1" , np .asarray ([1 , 2 , 3 ])),
23
23
"bar" : np .asarray ([1 , 2 , 3 ]),
24
+ "baz" : ("d1" , np .asarray ([4 , 5 , 6 ])),
24
25
}
25
26
)
26
27
@@ -82,20 +83,24 @@ def test_variables__multiple_specs(dummy_ds: xr.Dataset) -> None:
82
83
def test_variables__whole_ds (dummy_ds : xr .Dataset ) -> None :
83
84
spec_foo = ArrayLikeSpec ("foo" , "foo doc" , kind = "i" , ndim = 1 )
84
85
spec_bar = ArrayLikeSpec ("bar" , "bar doc" , kind = "i" , ndim = 1 )
86
+ spec_baz = ArrayLikeSpec ("baz" , "baz doc" , kind = "i" , ndim = 1 )
85
87
try :
86
88
SgkitVariables .register_variable (spec_foo )
87
89
with pytest .raises (ValueError , match = "`foo` already registered" ):
88
90
SgkitVariables .register_variable (spec_foo )
89
91
SgkitVariables .register_variable (spec_bar )
92
+ SgkitVariables .register_variable (spec_baz )
90
93
variables .validate (dummy_ds )
91
94
finally :
92
95
SgkitVariables .registered_variables .pop ("foo" , None )
93
96
SgkitVariables .registered_variables .pop ("bar" , None )
97
+ SgkitVariables .registered_variables .pop ("baz" , None )
94
98
95
99
96
100
def test_variables_in_multi_index (dummy_ds : xr .Dataset ) -> None :
97
101
# 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" )})
99
104
100
105
spec = ArrayLikeSpec ("foo" , "foo doc" , kind = "i" , ndim = 1 )
101
106
variables .validate (ds , spec )
0 commit comments