134134
135135
136136@pytest .fixture (scope = "module" , params = ZARR_FORMATS )
137- def default_zarr_version (request ) -> Generator [None , None ]:
137+ def default_zarr_format (request ) -> Generator [None , None ]:
138138 if has_zarr_v3 :
139- with zarr .config .set (default_zarr_version = request .param ):
139+ with zarr .config .set (default_zarr_format = request .param ):
140140 yield
141141 else :
142142 yield
143143
144144
145145def skip_if_zarr_format_3 (reason : str ):
146- if has_zarr_v3 and zarr .config ["default_zarr_version " ] == 3 :
146+ if has_zarr_v3 and zarr .config ["default_zarr_format " ] == 3 :
147147 pytest .skip (reason = f"Unsupported with zarr_format=3: { reason } " )
148148
149149
150150def skip_if_zarr_format_2 (reason : str ):
151- if not has_zarr_v3 or (zarr .config ["default_zarr_version " ] == 2 ):
151+ if not has_zarr_v3 or (zarr .config ["default_zarr_format " ] == 2 ):
152152 pytest .skip (reason = f"Unsupported with zarr_format=2: { reason } " )
153153
154154
@@ -2270,7 +2270,7 @@ def test_roundtrip_coordinates(self) -> None:
22702270
22712271
22722272@requires_zarr
2273- @pytest .mark .usefixtures ("default_zarr_version " )
2273+ @pytest .mark .usefixtures ("default_zarr_format " )
22742274class ZarrBase (CFEncodedBase ):
22752275 DIMENSION_KEY = "_ARRAY_DIMENSIONS"
22762276 zarr_version = 2
@@ -2675,40 +2675,35 @@ def test_write_persistence_modes(self, group) -> None:
26752675 assert_identical (original , actual )
26762676
26772677 def test_compressor_encoding (self ) -> None :
2678+ from numcodecs .blosc import Blosc
2679+
26782680 original = create_test_data ()
26792681 # specify a custom compressor
26802682
2681- if has_zarr_v3 and zarr .config .config ["default_zarr_version " ] == 3 :
2682- encoding_key = "codecs "
2683+ if has_zarr_v3 and zarr .config .config ["default_zarr_format " ] == 3 :
2684+ encoding_key = "compressors "
26832685 # all parameters need to be explicitly specified in order for the comparison to pass below
26842686 encoding = {
2687+ "serializer" : zarr .codecs .BytesCodec (endian = "little" ),
26852688 encoding_key : (
2686- zarr .codecs .BytesCodec (endian = "little" ),
2687- zarr .codecs .BloscCodec (
2689+ Blosc (
26882690 cname = "zstd" ,
26892691 clevel = 3 ,
26902692 shuffle = "shuffle" ,
26912693 typesize = 8 ,
26922694 blocksize = 0 ,
26932695 ),
2694- )
2696+ ),
26952697 }
26962698 else :
2697- from numcodecs .blosc import Blosc
2698-
2699- encoding_key = "compressor"
2700- encoding = {encoding_key : Blosc (cname = "zstd" , clevel = 3 , shuffle = 2 )}
2699+ encoding_key = "compressors" if has_zarr_v3 else "compressor"
2700+ encoding = {encoding_key : (Blosc (cname = "zstd" , clevel = 3 , shuffle = 2 ),)}
27012701
27022702 save_kwargs = dict (encoding = {"var1" : encoding })
27032703
27042704 with self .roundtrip (original , save_kwargs = save_kwargs ) as ds :
27052705 enc = ds ["var1" ].encoding [encoding_key ]
2706- if has_zarr_v3 and zarr .config .config ["default_zarr_version" ] == 3 :
2707- # TODO: figure out a cleaner way to do this comparison
2708- codecs = zarr .core .metadata .v3 .parse_codecs (enc )
2709- assert codecs == encoding [encoding_key ]
2710- else :
2711- assert enc == encoding [encoding_key ]
2706+ assert enc == encoding [encoding_key ]
27122707
27132708 def test_group (self ) -> None :
27142709 original = create_test_data ()
@@ -2846,14 +2841,9 @@ def test_check_encoding_is_consistent_after_append(self) -> None:
28462841 import numcodecs
28472842
28482843 encoding_value : Any
2849- if has_zarr_v3 and zarr .config .config ["default_zarr_version" ] == 3 :
2850- compressor = zarr .codecs .BloscCodec ()
2851- encoding_key = "codecs"
2852- encoding_value = [zarr .codecs .BytesCodec (), compressor ]
2853- else :
2854- compressor = numcodecs .Blosc ()
2855- encoding_key = "compressor"
2856- encoding_value = compressor
2844+ compressor = numcodecs .Blosc ()
2845+ encoding_key = "compressors" if has_zarr_v3 else "compressor"
2846+ encoding_value = compressor
28572847
28582848 encoding = {"da" : {encoding_key : encoding_value }}
28592849 ds .to_zarr (store_target , mode = "w" , encoding = encoding , ** self .version_kwargs )
@@ -6092,14 +6082,14 @@ def test_raise_writing_to_nczarr(self, mode) -> None:
60926082
60936083@requires_netCDF4
60946084@requires_dask
6095- @pytest .mark .usefixtures ("default_zarr_version " )
6085+ @pytest .mark .usefixtures ("default_zarr_format " )
60966086def test_pickle_open_mfdataset_dataset ():
60976087 with open_example_mfdataset (["bears.nc" ]) as ds :
60986088 assert_identical (ds , pickle .loads (pickle .dumps (ds )))
60996089
61006090
61016091@requires_zarr
6102- @pytest .mark .usefixtures ("default_zarr_version " )
6092+ @pytest .mark .usefixtures ("default_zarr_format " )
61036093def test_zarr_closing_internal_zip_store ():
61046094 store_name = "tmp.zarr.zip"
61056095 original_da = DataArray (np .arange (12 ).reshape ((3 , 4 )))
@@ -6110,7 +6100,7 @@ def test_zarr_closing_internal_zip_store():
61106100
61116101
61126102@requires_zarr
6113- @pytest .mark .usefixtures ("default_zarr_version " )
6103+ @pytest .mark .usefixtures ("default_zarr_format " )
61146104class TestZarrRegionAuto :
61156105 def test_zarr_region_auto_all (self , tmp_path ):
61166106 x = np .arange (0 , 50 , 10 )
@@ -6286,7 +6276,7 @@ def test_zarr_region_append(self, tmp_path):
62866276
62876277
62886278@requires_zarr
6289- @pytest .mark .usefixtures ("default_zarr_version " )
6279+ @pytest .mark .usefixtures ("default_zarr_format " )
62906280def test_zarr_region (tmp_path ):
62916281 x = np .arange (0 , 50 , 10 )
62926282 y = np .arange (0 , 20 , 2 )
@@ -6315,7 +6305,7 @@ def test_zarr_region(tmp_path):
63156305
63166306@requires_zarr
63176307@requires_dask
6318- @pytest .mark .usefixtures ("default_zarr_version " )
6308+ @pytest .mark .usefixtures ("default_zarr_format " )
63196309def test_zarr_region_chunk_partial (tmp_path ):
63206310 """
63216311 Check that writing to partial chunks with `region` fails, assuming `safe_chunks=False`.
@@ -6336,7 +6326,7 @@ def test_zarr_region_chunk_partial(tmp_path):
63366326
63376327@requires_zarr
63386328@requires_dask
6339- @pytest .mark .usefixtures ("default_zarr_version " )
6329+ @pytest .mark .usefixtures ("default_zarr_format " )
63406330def test_zarr_append_chunk_partial (tmp_path ):
63416331 t_coords = np .array ([np .datetime64 ("2020-01-01" ).astype ("datetime64[ns]" )])
63426332 data = np .ones ((10 , 10 ))
@@ -6374,7 +6364,7 @@ def test_zarr_append_chunk_partial(tmp_path):
63746364
63756365@requires_zarr
63766366@requires_dask
6377- @pytest .mark .usefixtures ("default_zarr_version " )
6367+ @pytest .mark .usefixtures ("default_zarr_format " )
63786368def test_zarr_region_chunk_partial_offset (tmp_path ):
63796369 # https://github.com/pydata/xarray/pull/8459#issuecomment-1819417545
63806370 store = tmp_path / "foo.zarr"
@@ -6394,7 +6384,7 @@ def test_zarr_region_chunk_partial_offset(tmp_path):
63946384
63956385@requires_zarr
63966386@requires_dask
6397- @pytest .mark .usefixtures ("default_zarr_version " )
6387+ @pytest .mark .usefixtures ("default_zarr_format " )
63986388def test_zarr_safe_chunk_append_dim (tmp_path ):
63996389 store = tmp_path / "foo.zarr"
64006390 data = np .ones ((20 ,))
@@ -6445,7 +6435,7 @@ def test_zarr_safe_chunk_append_dim(tmp_path):
64456435
64466436@requires_zarr
64476437@requires_dask
6448- @pytest .mark .usefixtures ("default_zarr_version " )
6438+ @pytest .mark .usefixtures ("default_zarr_format " )
64496439def test_zarr_safe_chunk_region (tmp_path ):
64506440 store = tmp_path / "foo.zarr"
64516441
0 commit comments