1717 ChunkCoords ,
1818 MemoryOrder ,
1919 ZarrFormat ,
20+ parse_dtype ,
2021)
2122from zarr .core .config import config
2223from zarr .core .group import AsyncGroup , ConsolidatedMetadata , GroupMetadata
2324from zarr .core .metadata import ArrayMetadataDict , ArrayV2Metadata , ArrayV3Metadata
25+ from zarr .core .metadata .v2 import _default_filters_and_compressor
2426from zarr .errors import NodeTypeValidationError
2527from zarr .storage import (
2628 StoreLike ,
@@ -400,7 +402,7 @@ async def save_array(
400402 arr : ndarray
401403 NumPy array with data to save.
402404 zarr_format : {2, 3, None}, optional
403- The zarr format to use when saving.
405+ The zarr format to use when saving (default is 3 if not specified) .
404406 path : str or None, optional
405407 The path within the store where the array will be saved.
406408 storage_options : dict
@@ -773,9 +775,9 @@ async def open_group(
773775
774776
775777async def create (
776- shape : ChunkCoords ,
778+ shape : ChunkCoords | int ,
777779 * , # Note: this is a change from v2
778- chunks : ChunkCoords | None = None , # TODO: v2 allowed chunks=True
780+ chunks : ChunkCoords | int | None = None , # TODO: v2 allowed chunks=True
779781 dtype : npt .DTypeLike | None = None ,
780782 compressor : dict [str , JSON ] | None = None , # TODO: default and type change
781783 fill_value : Any | None = 0 , # TODO: need type
@@ -797,7 +799,7 @@ async def create(
797799 meta_array : Any | None = None , # TODO: need type
798800 attributes : dict [str , JSON ] | None = None ,
799801 # v3 only
800- chunk_shape : ChunkCoords | None = None ,
802+ chunk_shape : ChunkCoords | int | None = None ,
801803 chunk_key_encoding : (
802804 ChunkKeyEncoding
803805 | tuple [Literal ["default" ], Literal ["." , "/" ]]
@@ -816,19 +818,45 @@ async def create(
816818 shape : int or tuple of ints
817819 Array shape.
818820 chunks : int or tuple of ints, optional
819- Chunk shape. If True, will be guessed from `shape` and `dtype`. If
820- False, will be set to `shape`, i.e., single chunk for the whole array.
821- If an int, the chunk size in each dimension will be given by the value
822- of `chunks`. Default is True.
821+ The shape of the array's chunks.
822+ V2 only. V3 arrays should use `chunk_shape` instead.
823+ If not specified, default values are guessed based on the shape and dtype.
823824 dtype : str or dtype, optional
824825 NumPy dtype.
826+ chunk_shape : int or tuple of ints, optional
827+ The shape of the Array's chunks (default is None).
828+ V3 only. V2 arrays should use `chunks` instead.
829+ chunk_key_encoding : ChunkKeyEncoding, optional
830+ A specification of how the chunk keys are represented in storage.
831+ V3 only. V2 arrays should use `dimension_separator` instead.
832+ Default is ``("default", "/")``.
833+ codecs : Sequence of Codecs or dicts, optional
834+ An iterable of Codec or dict serializations of Codecs. The elements of
835+ this collection specify the transformation from array values to stored bytes.
836+ V3 only. V2 arrays should use ``filters`` and ``compressor`` instead.
837+
838+ If no codecs are provided, default codecs will be used:
839+
840+ - For numeric arrays, the default is ``BytesCodec`` and ``ZstdCodec``.
841+ - For Unicode strings, the default is ``VLenUTF8Codec``.
842+ - For bytes or objects, the default is ``VLenBytesCodec``.
843+
844+ These defaults can be changed by modifying the value of ``array.v3_default_codecs`` in :mod:`zarr.core.config`.
825845 compressor : Codec, optional
826- Primary compressor.
827- fill_value : object
846+ Primary compressor to compress chunk data.
847+ V2 only. V3 arrays should use ``codecs`` instead.
848+
849+ If neither ``compressor`` nor ``filters`` are provided, a default compressor will be used:
850+
851+ - For numeric arrays, the default is ``ZstdCodec``.
852+ - For Unicode strings, the default is ``VLenUTF8Codec``.
853+ - For bytes or objects, the default is ``VLenBytesCodec``.
854+
855+ These defaults can be changed by modifying the value of ``array.v2_default_compressor`` in :mod:`zarr.core.config`. fill_value : object
828856 Default value to use for uninitialized portions of the array.
829857 order : {'C', 'F'}, optional
830858 Memory layout to be used within each chunk.
831- Default is set in Zarr's config (` array.order`) .
859+ If not specified, default is taken from the Zarr config ``` array.order``` .
832860 store : Store or str
833861 Store or path to directory in file system or name of zip file.
834862 synchronizer : object, optional
@@ -843,6 +871,8 @@ async def create(
843871 for storage of both chunks and metadata.
844872 filters : sequence of Codecs, optional
845873 Sequence of filters to use to encode chunk data prior to compression.
874+ V2 only. If neither ``compressor`` nor ``filters`` are provided, a default
875+ compressor will be used. (see ``compressor`` for details).
846876 cache_metadata : bool, optional
847877 If True, array configuration metadata will be cached for the
848878 lifetime of the object. If False, array metadata will be reloaded
@@ -858,7 +888,8 @@ async def create(
858888 A codec to encode object arrays, only needed if dtype=object.
859889 dimension_separator : {'.', '/'}, optional
860890 Separator placed between the dimensions of a chunk.
861-
891+ V2 only. V3 arrays should use ``chunk_key_encoding`` instead.
892+ Default is ".".
862893 .. versionadded:: 2.8
863894
864895 write_empty_chunks : bool, optional
@@ -874,6 +905,7 @@ async def create(
874905
875906 zarr_format : {2, 3, None}, optional
876907 The zarr format to use when saving.
908+ Default is 3.
877909 meta_array : array-like, optional
878910 An array instance to use for determining arrays to create and return
879911 to users. Use `numpy.empty(())` by default.
@@ -893,9 +925,13 @@ async def create(
893925 or _default_zarr_version ()
894926 )
895927
896- if zarr_format == 2 and chunks is None :
897- chunks = shape
898- elif zarr_format == 3 and chunk_shape is None :
928+ if zarr_format == 2 :
929+ if chunks is None :
930+ chunks = shape
931+ dtype = parse_dtype (dtype , zarr_format )
932+ if not filters and not compressor :
933+ filters , compressor = _default_filters_and_compressor (dtype )
934+ elif zarr_format == 3 and chunk_shape is None : # type: ignore[redundant-expr]
899935 if chunks is not None :
900936 chunk_shape = chunks
901937 chunks = None
@@ -1103,6 +1139,8 @@ async def open_array(
11031139 ----------
11041140 store : Store or str
11051141 Store or path to directory in file system or name of zip file.
1142+ zarr_version : {2, 3, None}, optional
1143+ The zarr format to use when saving. Deprecated in favor of zarr_format.
11061144 zarr_format : {2, 3, None}, optional
11071145 The zarr format to use when saving.
11081146 path : str, optional
0 commit comments