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
@@ -2439,7 +2439,7 @@ def test_warning_on_bad_chunks(self) -> None:
24392439 with warnings .catch_warnings ():
24402440 warnings .filterwarnings (
24412441 "ignore" ,
2442- message = ".*Zarr version 3 specification.*" ,
2442+ message = ".*Zarr format 3 specification.*" ,
24432443 category = UserWarning ,
24442444 )
24452445 with self .roundtrip (original , open_kwargs = kwargs ) as actual :
@@ -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- original = create_test_data ()
26792678 # specify a custom compressor
2680-
2681- if has_zarr_v3 and zarr .config .config ["default_zarr_version " ] == 3 :
2682- encoding_key = "codecs "
2679+ original = create_test_data ()
2680+ if has_zarr_v3 and zarr .config .config ["default_zarr_format " ] == 3 :
2681+ encoding_key = "compressors "
26832682 # all parameters need to be explicitly specified in order for the comparison to pass below
26842683 encoding = {
2684+ "serializer" : zarr .codecs .BytesCodec (endian = "little" ),
26852685 encoding_key : (
2686- zarr .codecs .BytesCodec (endian = "little" ),
26872686 zarr .codecs .BloscCodec (
26882687 cname = "zstd" ,
26892688 clevel = 3 ,
26902689 shuffle = "shuffle" ,
26912690 typesize = 8 ,
26922691 blocksize = 0 ,
26932692 ),
2694- )
2693+ ),
26952694 }
26962695 else :
26972696 from numcodecs .blosc import Blosc
26982697
2699- encoding_key = "compressor"
2700- encoding = {encoding_key : Blosc (cname = "zstd" , clevel = 3 , shuffle = 2 )}
2698+ encoding_key = "compressors" if has_zarr_v3 else "compressor"
2699+ comp = Blosc (cname = "zstd" , clevel = 3 , shuffle = 2 )
2700+ encoding = {encoding_key : (comp ,) if has_zarr_v3 else comp }
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,12 @@ 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 :
2844+ if has_zarr_v3 and zarr .config .config ["default_zarr_format " ] == 3 :
28502845 compressor = zarr .codecs .BloscCodec ()
2851- encoding_key = "codecs"
2852- encoding_value = [zarr .codecs .BytesCodec (), compressor ]
28532846 else :
28542847 compressor = numcodecs .Blosc ()
2855- encoding_key = "compressor"
2856- encoding_value = compressor
2848+ encoding_key = "compressors" if has_zarr_v3 else "compressor"
2849+ encoding_value = ( compressor ,) if has_zarr_v3 else compressor
28572850
28582851 encoding = {"da" : {encoding_key : encoding_value }}
28592852 ds .to_zarr (store_target , mode = "w" , encoding = encoding , ** self .version_kwargs )
@@ -2995,7 +2988,7 @@ def test_no_warning_from_open_emptydim_with_chunks(self) -> None:
29952988 with warnings .catch_warnings ():
29962989 warnings .filterwarnings (
29972990 "ignore" ,
2998- message = ".*Zarr version 3 specification.*" ,
2991+ message = ".*Zarr format 3 specification.*" ,
29992992 category = UserWarning ,
30002993 )
30012994 with self .roundtrip (ds , open_kwargs = dict (chunks = {"a" : 1 })) as ds_reload :
@@ -5479,7 +5472,7 @@ def test_dataarray_to_netcdf_no_name_pathlib(self) -> None:
54795472@requires_zarr
54805473class TestDataArrayToZarr :
54815474 def skip_if_zarr_python_3_and_zip_store (self , store ) -> None :
5482- if has_zarr_v3 and isinstance (store , zarr .storage .zip . ZipStore ):
5475+ if has_zarr_v3 and isinstance (store , zarr .storage .ZipStore ):
54835476 pytest .skip (
54845477 reason = "zarr-python 3.x doesn't support reopening ZipStore with a new mode."
54855478 )
@@ -5786,7 +5779,7 @@ def test_extract_zarr_variable_encoding() -> None:
57865779 var = xr .Variable ("x" , [1 , 2 ])
57875780 actual = backends .zarr .extract_zarr_variable_encoding (var )
57885781 assert "chunks" in actual
5789- assert actual ["chunks" ] is None
5782+ assert actual ["chunks" ] == ( "auto" if has_zarr_v3 else None )
57905783
57915784 var = xr .Variable ("x" , [1 , 2 ], encoding = {"chunks" : (1 ,)})
57925785 actual = backends .zarr .extract_zarr_variable_encoding (var )
@@ -6092,14 +6085,14 @@ def test_raise_writing_to_nczarr(self, mode) -> None:
60926085
60936086@requires_netCDF4
60946087@requires_dask
6095- @pytest .mark .usefixtures ("default_zarr_version " )
6088+ @pytest .mark .usefixtures ("default_zarr_format " )
60966089def test_pickle_open_mfdataset_dataset ():
60976090 with open_example_mfdataset (["bears.nc" ]) as ds :
60986091 assert_identical (ds , pickle .loads (pickle .dumps (ds )))
60996092
61006093
61016094@requires_zarr
6102- @pytest .mark .usefixtures ("default_zarr_version " )
6095+ @pytest .mark .usefixtures ("default_zarr_format " )
61036096def test_zarr_closing_internal_zip_store ():
61046097 store_name = "tmp.zarr.zip"
61056098 original_da = DataArray (np .arange (12 ).reshape ((3 , 4 )))
@@ -6110,7 +6103,7 @@ def test_zarr_closing_internal_zip_store():
61106103
61116104
61126105@requires_zarr
6113- @pytest .mark .usefixtures ("default_zarr_version " )
6106+ @pytest .mark .usefixtures ("default_zarr_format " )
61146107class TestZarrRegionAuto :
61156108 def test_zarr_region_auto_all (self , tmp_path ):
61166109 x = np .arange (0 , 50 , 10 )
@@ -6286,7 +6279,7 @@ def test_zarr_region_append(self, tmp_path):
62866279
62876280
62886281@requires_zarr
6289- @pytest .mark .usefixtures ("default_zarr_version " )
6282+ @pytest .mark .usefixtures ("default_zarr_format " )
62906283def test_zarr_region (tmp_path ):
62916284 x = np .arange (0 , 50 , 10 )
62926285 y = np .arange (0 , 20 , 2 )
@@ -6315,7 +6308,7 @@ def test_zarr_region(tmp_path):
63156308
63166309@requires_zarr
63176310@requires_dask
6318- @pytest .mark .usefixtures ("default_zarr_version " )
6311+ @pytest .mark .usefixtures ("default_zarr_format " )
63196312def test_zarr_region_chunk_partial (tmp_path ):
63206313 """
63216314 Check that writing to partial chunks with `region` fails, assuming `safe_chunks=False`.
@@ -6336,7 +6329,7 @@ def test_zarr_region_chunk_partial(tmp_path):
63366329
63376330@requires_zarr
63386331@requires_dask
6339- @pytest .mark .usefixtures ("default_zarr_version " )
6332+ @pytest .mark .usefixtures ("default_zarr_format " )
63406333def test_zarr_append_chunk_partial (tmp_path ):
63416334 t_coords = np .array ([np .datetime64 ("2020-01-01" ).astype ("datetime64[ns]" )])
63426335 data = np .ones ((10 , 10 ))
@@ -6374,7 +6367,7 @@ def test_zarr_append_chunk_partial(tmp_path):
63746367
63756368@requires_zarr
63766369@requires_dask
6377- @pytest .mark .usefixtures ("default_zarr_version " )
6370+ @pytest .mark .usefixtures ("default_zarr_format " )
63786371def test_zarr_region_chunk_partial_offset (tmp_path ):
63796372 # https://github.com/pydata/xarray/pull/8459#issuecomment-1819417545
63806373 store = tmp_path / "foo.zarr"
@@ -6394,7 +6387,7 @@ def test_zarr_region_chunk_partial_offset(tmp_path):
63946387
63956388@requires_zarr
63966389@requires_dask
6397- @pytest .mark .usefixtures ("default_zarr_version " )
6390+ @pytest .mark .usefixtures ("default_zarr_format " )
63986391def test_zarr_safe_chunk_append_dim (tmp_path ):
63996392 store = tmp_path / "foo.zarr"
64006393 data = np .ones ((20 ,))
@@ -6445,7 +6438,7 @@ def test_zarr_safe_chunk_append_dim(tmp_path):
64456438
64466439@requires_zarr
64476440@requires_dask
6448- @pytest .mark .usefixtures ("default_zarr_version " )
6441+ @pytest .mark .usefixtures ("default_zarr_format " )
64496442def test_zarr_safe_chunk_region (tmp_path ):
64506443 store = tmp_path / "foo.zarr"
64516444
0 commit comments