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
24+
25+
26+ _USING_ZARR_PYTHON_3 = packaging .version .parse (zarr .__version__ ).major >= 3
2327
2428
2529class XarrayTensorstoreTest (parameterized .TestCase ):
@@ -145,13 +149,19 @@ def test_open_zarr_from_uri(self):
145149 opened = xarray_tensorstore .open_zarr ('file://' + path )
146150 xarray .testing .assert_identical (source , opened )
147151
148- def test_read_dataset (self ):
152+ @parameterized .parameters (
153+ {'zarr_format' : 2 },
154+ {'zarr_format' : 3 },
155+ )
156+ def test_read_dataset (self , zarr_format ):
157+ if not _USING_ZARR_PYTHON_3 and zarr_format == 3 :
158+ self .skipTest ('zarr format 3 is not supported in zarr < 3.0.0' )
149159 source = xarray .Dataset (
150160 {'baz' : (('x' , 'y' , 'z' ), np .arange (24 ).reshape (2 , 3 , 4 ))},
151161 coords = {'x' : np .arange (2 )},
152162 )
153163 path = self .create_tempdir ().full_path
154- source .chunk ().to_zarr (path )
164+ source .chunk ().to_zarr (path , zarr_format = zarr_format )
155165
156166 opened = xarray_tensorstore .open_zarr (path )
157167 read = xarray_tensorstore .read (opened )
@@ -160,15 +170,21 @@ def test_read_dataset(self):
160170 self .assertIsNotNone (read .variables ['baz' ]._data .future )
161171 xarray .testing .assert_identical (read , source )
162172
163- def test_read_dataarray (self ):
173+ @parameterized .parameters (
174+ {'zarr_format' : 2 },
175+ {'zarr_format' : 3 },
176+ )
177+ def test_read_dataarray (self , zarr_format ):
178+ if not _USING_ZARR_PYTHON_3 and zarr_format == 3 :
179+ self .skipTest ('zarr format 3 is not supported in zarr < 3.0.0' )
164180 source = xarray .DataArray (
165181 np .arange (24 ).reshape (2 , 3 , 4 ),
166182 dims = ('x' , 'y' , 'z' ),
167183 name = 'baz' ,
168184 coords = {'x' : np .arange (2 )},
169185 )
170186 path = self .create_tempdir ().full_path
171- source .to_dataset ().chunk ().to_zarr (path )
187+ source .to_dataset ().chunk ().to_zarr (path , zarr_format = zarr_format )
172188
173189 opened = xarray_tensorstore .open_zarr (path )['baz' ]
174190 read = xarray_tensorstore .read (opened )
0 commit comments