2626_USING_ZARR_PYTHON_3 = packaging .version .parse (zarr .__version__ ).major >= 3
2727
2828test_cases = [
29- {
30- 'testcase_name' : 'base' ,
31- 'transform' : lambda ds : ds ,
32- },
33- {
34- 'testcase_name' : 'transposed' ,
35- 'transform' : lambda ds : ds .transpose ('z' , 'x' , 'y' ),
36- },
37- {
38- 'testcase_name' : 'basic_int' ,
39- 'transform' : lambda ds : ds .isel (y = 1 ),
40- },
41- {
42- 'testcase_name' : 'negative_int' ,
43- 'transform' : lambda ds : ds .isel (y = - 1 ),
44- },
45- {
46- 'testcase_name' : 'basic_slice' ,
47- 'transform' : lambda ds : ds .isel (z = slice (2 )),
48- },
49- {
50- 'testcase_name' : 'full_slice' ,
51- 'transform' : lambda ds : ds .isel (z = slice (0 , 4 )),
52- },
53- {
54- 'testcase_name' : 'out_of_bounds_slice' ,
55- 'transform' : lambda ds : ds .isel (z = slice (0 , 10 )),
56- },
57- {
58- 'testcase_name' : 'strided_slice' ,
59- 'transform' : lambda ds : ds .isel (z = slice (0 , None , 2 )),
60- },
61- {
62- 'testcase_name' : 'negative_stride_slice' ,
63- 'transform' : lambda ds : ds .isel (z = slice (None , None , - 1 )),
64- },
65- {
66- 'testcase_name' : 'repeated_indexing' ,
67- 'transform' : lambda ds : ds .isel (z = slice (1 , None )).isel (z = 0 ),
68- },
69- {
70- 'testcase_name' : 'oindex' ,
71- # includes repeated, negative and out of order indices
72- 'transform' : lambda ds : ds .isel (x = [0 ], y = [1 , 1 ], z = [1 , - 1 , 0 ]),
73- },
74- {
75- 'testcase_name' : 'vindex' ,
76- 'transform' : lambda ds : ds .isel (x = ('w' , [0 , 1 ]), y = ('w' , [1 , 2 ])),
77- },
78- {
79- 'testcase_name' : 'mixed_indexing_types' ,
80- 'transform' : lambda ds : ds .isel (x = 0 , y = slice (2 ), z = [- 1 ]),
81- },
82- {
83- 'testcase_name' : 'select_a_variable' ,
84- 'transform' : lambda ds : ds ['foo' ],
85- },
29+ {
30+ 'testcase_name' : 'base' ,
31+ 'transform' : lambda ds : ds ,
32+ },
33+ {
34+ 'testcase_name' : 'transposed' ,
35+ 'transform' : lambda ds : ds .transpose ('z' , 'x' , 'y' ),
36+ },
37+ {
38+ 'testcase_name' : 'basic_int' ,
39+ 'transform' : lambda ds : ds .isel (y = 1 ),
40+ },
41+ {
42+ 'testcase_name' : 'negative_int' ,
43+ 'transform' : lambda ds : ds .isel (y = - 1 ),
44+ },
45+ {
46+ 'testcase_name' : 'basic_slice' ,
47+ 'transform' : lambda ds : ds .isel (z = slice (2 )),
48+ },
49+ {
50+ 'testcase_name' : 'full_slice' ,
51+ 'transform' : lambda ds : ds .isel (z = slice (0 , 4 )),
52+ },
53+ {
54+ 'testcase_name' : 'out_of_bounds_slice' ,
55+ 'transform' : lambda ds : ds .isel (z = slice (0 , 10 )),
56+ },
57+ {
58+ 'testcase_name' : 'strided_slice' ,
59+ 'transform' : lambda ds : ds .isel (z = slice (0 , None , 2 )),
60+ },
61+ {
62+ 'testcase_name' : 'negative_stride_slice' ,
63+ 'transform' : lambda ds : ds .isel (z = slice (None , None , - 1 )),
64+ },
65+ {
66+ 'testcase_name' : 'repeated_indexing' ,
67+ 'transform' : lambda ds : ds .isel (z = slice (1 , None )).isel (z = 0 ),
68+ },
69+ {
70+ 'testcase_name' : 'oindex' ,
71+ # includes repeated, negative and out of order indices
72+ 'transform' : lambda ds : ds .isel (x = [0 ], y = [1 , 1 ], z = [1 , - 1 , 0 ]),
73+ },
74+ {
75+ 'testcase_name' : 'vindex' ,
76+ 'transform' : lambda ds : ds .isel (x = ('w' , [0 , 1 ]), y = ('w' , [1 , 2 ])),
77+ },
78+ {
79+ 'testcase_name' : 'mixed_indexing_types' ,
80+ 'transform' : lambda ds : ds .isel (x = 0 , y = slice (2 ), z = [- 1 ]),
81+ },
82+ {
83+ 'testcase_name' : 'select_a_variable' ,
84+ 'transform' : lambda ds : ds ['foo' ],
85+ },
8686]
8787
8888
@@ -128,16 +128,18 @@ def test_open_concatenated_zarrs(self, transform):
128128 },
129129 attrs = {'global' : 'global metadata' },
130130 )
131- for x in [range (0 ,2 ), range (3 , 5 )]
131+ for x in [range (0 , 2 ), range (3 , 5 )]
132132 ]
133133
134134 zarr_dir = self .create_tempdir ().full_path
135- paths = [f" { zarr_dir } /{ i } " for i in range (len (sources ))]
135+ paths = [f' { zarr_dir } /{ i } ' for i in range (len (sources ))]
136136 for source , path in zip (sources , paths , strict = True ):
137137 source .chunk ().to_zarr (path )
138138
139- expected = transform (xarray .concat (sources , dim = "x" ))
140- actual = transform (xarray_tensorstore .open_concatenated_zarrs (paths , concat_dim = "x" )).compute ()
139+ expected = transform (xarray .concat (sources , dim = 'x' ))
140+ actual = transform (
141+ xarray_tensorstore .open_concatenated_zarrs (paths , concat_dim = 'x' )
142+ ).compute ()
141143 xarray .testing .assert_identical (actual , expected )
142144
143145 @parameterized .parameters (
@@ -172,26 +174,32 @@ def test_compute(self):
172174 self .assertNotIsInstance (computed_data , tensorstore .TensorStore )
173175
174176 def test_open_zarr_from_uri (self ):
175- source = xarray .Dataset ({'baz' : (('x' , 'y' , 'z' ), np .arange (24 ).reshape (2 , 3 , 4 ))})
177+ source = xarray .Dataset (
178+ {'baz' : (('x' , 'y' , 'z' ), np .arange (24 ).reshape (2 , 3 , 4 ))}
179+ )
176180 path = self .create_tempdir ().full_path
177181 source .chunk ().to_zarr (path )
178182
179183 opened = xarray_tensorstore .open_zarr ('file://' + path )
180184 xarray .testing .assert_identical (source , opened )
181185
182186 @parameterized .parameters (
183- {'zarr_format' : 2 },
184- {'zarr_format' : 3 },
187+ {'zarr_format' : 2 , 'consolidated' : True },
188+ {'zarr_format' : 3 , 'consolidated' : True },
189+ {'zarr_format' : 2 , 'consolidated' : False },
190+ {'zarr_format' : 3 , 'consolidated' : False },
185191 )
186- def test_read_dataset (self , zarr_format ):
192+ def test_read_dataset (self , zarr_format : int , consolidated : bool ):
187193 if not _USING_ZARR_PYTHON_3 and zarr_format == 3 :
188194 self .skipTest ('zarr format 3 is not supported in zarr < 3.0.0' )
189195 source = xarray .Dataset (
190196 {'baz' : (('x' , 'y' , 'z' ), np .arange (24 ).reshape (2 , 3 , 4 ))},
191197 coords = {'x' : np .arange (2 )},
192198 )
193199 path = self .create_tempdir ().full_path
194- source .chunk ().to_zarr (path , zarr_format = zarr_format )
200+ source .chunk ().to_zarr (
201+ path , zarr_format = zarr_format , consolidated = consolidated
202+ )
195203
196204 opened = xarray_tensorstore .open_zarr (path )
197205 read = xarray_tensorstore .read (opened )
@@ -204,8 +212,8 @@ def test_read_dataset(self, zarr_format):
204212 {'zarr_format' : 2 },
205213 {'zarr_format' : 3 },
206214 )
207- def test_read_dataarray (self , zarr_format ):
208- if not _USING_ZARR_PYTHON_3 and zarr_format == 3 :
215+ def test_read_dataarray (self , zarr_format : int ):
216+ if not _USING_ZARR_PYTHON_3 and zarr_format == 3 :
209217 self .skipTest ('zarr format 3 is not supported in zarr < 3.0.0' )
210218 source = xarray .DataArray (
211219 np .arange (24 ).reshape (2 , 3 , 4 ),
0 commit comments