1414from absl .testing import absltest
1515from absl .testing import parameterized
1616import numpy as np
17+ import packaging
1718import pandas as pd
1819import pytest
1920import tensorstore
2021import xarray
21- from xarray .core import indexing
2222import xarray_tensorstore
23+ import zarr
2324
2425
2526class XarrayTensorstoreTest (parameterized .TestCase ):
@@ -145,13 +146,19 @@ def test_open_zarr_from_uri(self):
145146 opened = xarray_tensorstore .open_zarr ('file://' + path )
146147 xarray .testing .assert_identical (source , opened )
147148
148- def test_read_dataset (self ):
149+ @parameterized .parameters (
150+ {'zarr_format' : 2 },
151+ {'zarr_format' : 3 },
152+ )
153+ def test_read_dataset (self , zarr_format ):
154+ if packaging .version .parse (zarr .__version__ ).major < 3 and zarr_format == 3 :
155+ self .skipTest ('zarr format 3 is not supported in zarr < 3.0.0' )
149156 source = xarray .Dataset (
150157 {'baz' : (('x' , 'y' , 'z' ), np .arange (24 ).reshape (2 , 3 , 4 ))},
151158 coords = {'x' : np .arange (2 )},
152159 )
153160 path = self .create_tempdir ().full_path
154- source .chunk ().to_zarr (path )
161+ source .chunk ().to_zarr (path , zarr_format = zarr_format )
155162
156163 opened = xarray_tensorstore .open_zarr (path )
157164 read = xarray_tensorstore .read (opened )
@@ -160,15 +167,21 @@ def test_read_dataset(self):
160167 self .assertIsNotNone (read .variables ['baz' ]._data .future )
161168 xarray .testing .assert_identical (read , source )
162169
163- def test_read_dataarray (self ):
170+ @parameterized .parameters (
171+ {'zarr_format' : 2 },
172+ {'zarr_format' : 3 },
173+ )
174+ def test_read_dataarray (self , zarr_format ):
175+ if packaging .version .parse (zarr .__version__ ).major < 3 and zarr_format == 3 :
176+ self .skipTest ('zarr format 3 is not supported in zarr < 3.0.0' )
164177 source = xarray .DataArray (
165178 np .arange (24 ).reshape (2 , 3 , 4 ),
166179 dims = ('x' , 'y' , 'z' ),
167180 name = 'baz' ,
168181 coords = {'x' : np .arange (2 )},
169182 )
170183 path = self .create_tempdir ().full_path
171- source .to_dataset ().chunk ().to_zarr (path )
184+ source .to_dataset ().chunk ().to_zarr (path , zarr_format = zarr_format )
172185
173186 opened = xarray_tensorstore .open_zarr (path )['baz' ]
174187 read = xarray_tensorstore .read (opened )
0 commit comments