9797from zarr .errors import MetadataValidationError
9898from zarr .registry import (
9999 _parse_array_array_codec ,
100+ _parse_array_bytes_codec ,
100101 _parse_bytes_bytes_codec ,
101102 _resolve_codec ,
102103 get_pipeline_class ,
@@ -385,6 +386,7 @@ async def _create(
385386 ) -> AsyncArray [ArrayV3Metadata ] | AsyncArray [ArrayV2Metadata ]: ...
386387
387388 @classmethod
389+ # @deprecated("Use `zarr.api.asynchronous.create_array` instead.")
388390 async def _create (
389391 cls ,
390392 store : StoreLike ,
@@ -417,6 +419,7 @@ async def _create(
417419 config : ArrayConfig | ArrayConfigParams | None = None ,
418420 ) -> AsyncArray [ArrayV2Metadata ] | AsyncArray [ArrayV3Metadata ]:
419421 """
422+ Deprecated in favor of `zarr.api.asynchronous.create_array`.
420423 Method to create a new asynchronous array instance.
421424
422425 Parameters
@@ -677,10 +680,10 @@ async def _create_v2(
677680 dimension_separator = "."
678681
679682 dtype = parse_dtype (dtype , zarr_format = 2 )
680- if not filters :
681- filters = _default_filters (dtype )
682- if not compressor :
683- compressor = _default_compressor (dtype )
683+ # if not filters:
684+ # filters = _default_filters(dtype)
685+ # if not compressor:
686+ # compressor = _default_compressor(dtype)
684687
685688 # inject VLenUTF8 for str dtype if not already present
686689 if np .issubdtype (dtype , np .str_ ):
@@ -1530,6 +1533,7 @@ class Array:
15301533 _async_array : AsyncArray [ArrayV3Metadata ] | AsyncArray [ArrayV2Metadata ]
15311534
15321535 @classmethod
1536+ # @deprecated("Use `zarr.create_array` instead.")
15331537 @_deprecate_positional_args
15341538 def _create (
15351539 cls ,
@@ -1561,7 +1565,8 @@ def _create(
15611565 overwrite : bool = False ,
15621566 config : ArrayConfig | ArrayConfigParams | None = None ,
15631567 ) -> Array :
1564- """Creates a new Array instance from an initialized store.
1568+ """Deprecated in favor of `zarr.create_array`.
1569+ Creates a new Array instance from an initialized store.
15651570
15661571 Parameters
15671572 ----------
@@ -3504,6 +3509,7 @@ def _get_default_codecs(
35043509 | numcodecs .abc .Codec
35053510 | Literal ["auto" ]
35063511)
3512+ ArrayBytesCodecParam : TypeAlias = dict [str , JSON ] | ArrayBytesCodec | Literal ["auto" ]
35073513
35083514
35093515class ShardsConfigParam (TypedDict ):
@@ -3524,6 +3530,7 @@ async def create_array(
35243530 shards : ShardsParam | None = None ,
35253531 filters : FiltersParam = "auto" ,
35263532 compressors : CompressorsParam = "auto" ,
3533+ array_bytes_codec : ArrayBytesCodecParam | None = "auto" ,
35273534 fill_value : Any | None = 0 ,
35283535 order : MemoryOrder | None = None ,
35293536 zarr_format : ZarrFormat | None = 3 ,
@@ -3580,6 +3587,10 @@ async def create_array(
35803587 For Zarr v2, a "compressor" can be any numcodecs codec. Only a single compressor may be provided for Zarr v2.
35813588 If no ``compressors`` are provided, a default compressor will be used.
35823589 These defaults can be changed by modifying the value of ``array.v2_default_compressor`` in :mod:`zarr.core.config`.
3590+ array_bytes_codec : dict[str, JSON] | ArrayBytesCodec, optional
3591+ Array-to-bytes codec to use for encoding the array data.
3592+ Zarr v3 only. Zarr v2 arrays use implicit array-to-bytes conversion.
3593+ If no ``array_bytes_codec`` is provided, the `zarr.codecs.BytesCodec` codec will be used.
35833594 fill_value : Any, optional
35843595 Fill value for the array.
35853596 order : {"C", "F"}, optional
@@ -3680,7 +3691,10 @@ async def create_array(
36803691 )
36813692 else :
36823693 array_array , array_bytes , bytes_bytes = _parse_chunk_encoding_v3 (
3683- compressors = compressors , filters = filters , dtype = dtype_parsed
3694+ compressors = compressors ,
3695+ filters = filters ,
3696+ array_bytes_codec = array_bytes_codec ,
3697+ dtype = dtype_parsed ,
36843698 )
36853699 sub_codecs = cast (tuple [Codec , ...], (* array_array , array_bytes , * bytes_bytes ))
36863700 codecs_out : tuple [Codec , ...]
@@ -3825,7 +3839,11 @@ def _parse_chunk_encoding_v2(
38253839 if compressor == "auto" :
38263840 _compressor = default_compressor
38273841 else :
3828- if isinstance (compressor , Iterable ) and not isinstance (compressor , dict ):
3842+ if (
3843+ isinstance (compressor , Iterable )
3844+ and not isinstance (compressor , dict )
3845+ and len (compressor ) > 1
3846+ ):
38293847 msg = f"For Zarr v2 arrays, the `compressor` must be a single codec. Got an iterable with type { type (compressor )} instead."
38303848 raise TypeError (msg )
38313849 _compressor = parse_compressor (compressor )
@@ -3846,8 +3864,9 @@ def _parse_chunk_encoding_v2(
38463864
38473865def _parse_chunk_encoding_v3 (
38483866 * ,
3849- compressors : CompressorsParam ,
3850- filters : FiltersParam ,
3867+ compressors : CompressorsParam | None ,
3868+ filters : FiltersParam | None ,
3869+ array_bytes_codec : ArrayBytesCodecParam | None ,
38513870 dtype : np .dtype [Any ],
38523871) -> tuple [tuple [ArrayArrayCodec , ...], ArrayBytesCodec , tuple [BytesBytesCodec , ...]]:
38533872 """
@@ -3864,6 +3883,8 @@ def _parse_chunk_encoding_v3(
38643883 else :
38653884 if isinstance (compressors , dict | Codec ):
38663885 maybe_bytes_bytes = (compressors ,)
3886+ elif compressors is None :
3887+ maybe_bytes_bytes = ()
38673888 else :
38683889 maybe_bytes_bytes = cast (Iterable [Codec | dict [str , JSON ]], compressors )
38693890
@@ -3874,8 +3895,15 @@ def _parse_chunk_encoding_v3(
38743895 else :
38753896 if isinstance (filters , dict | Codec ):
38763897 maybe_array_array = (filters ,)
3898+ elif filters is None :
3899+ maybe_array_array = ()
38773900 else :
38783901 maybe_array_array = cast (Iterable [Codec | dict [str , JSON ]], filters )
38793902 out_array_array = tuple (_parse_array_array_codec (c ) for c in maybe_array_array )
38803903
3881- return out_array_array , default_array_bytes , out_bytes_bytes
3904+ if array_bytes_codec == "auto" :
3905+ out_array_bytes = default_array_bytes
3906+ else :
3907+ out_array_bytes = _parse_array_bytes_codec (array_bytes_codec )
3908+
3909+ return out_array_array , out_array_bytes , out_bytes_bytes
0 commit comments