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 ,
@@ -401,7 +403,7 @@ async def save_array(
401403 arr : ndarray
402404 NumPy array with data to save.
403405 zarr_format : {2, 3, None}, optional
404- The zarr format to use when saving.
406+ The zarr format to use when saving (default is 3 if not specified) .
405407 path : str or None, optional
406408 The path within the store where the array will be saved.
407409 storage_options : dict
@@ -817,19 +819,45 @@ async def create(
817819 shape : int or tuple of ints
818820 Array shape.
819821 chunks : int or tuple of ints, optional
820- Chunk shape. If True, will be guessed from `shape` and `dtype`. If
821- False, will be set to `shape`, i.e., single chunk for the whole array.
822- If an int, the chunk size in each dimension will be given by the value
823- of `chunks`. Default is True.
822+ The shape of the array's chunks.
823+ V2 only. V3 arrays should use `chunk_shape` instead.
824+ If not specified, default values are guessed based on the shape and dtype.
824825 dtype : str or dtype, optional
825826 NumPy dtype.
827+ chunk_shape : int or tuple of ints, optional
828+ The shape of the Array's chunks (default is None).
829+ V3 only. V2 arrays should use `chunks` instead.
830+ chunk_key_encoding : ChunkKeyEncoding, optional
831+ A specification of how the chunk keys are represented in storage.
832+ V3 only. V2 arrays should use `dimension_separator` instead.
833+ Default is ``("default", "/")``.
834+ codecs : Sequence of Codecs or dicts, optional
835+ An iterable of Codec or dict serializations of Codecs. The elements of
836+ this collection specify the transformation from array values to stored bytes.
837+ V3 only. V2 arrays should use ``filters`` and ``compressor`` instead.
838+
839+ If no codecs are provided, default codecs will be used:
840+
841+ - For numeric arrays, the default is ``BytesCodec`` and ``ZstdCodec``.
842+ - For Unicode strings, the default is ``VLenUTF8Codec``.
843+ - For bytes or objects, the default is ``VLenBytesCodec``.
844+
845+ These defaults can be changed by modifying the value of ``array.v3_default_codecs`` in :mod:`zarr.core.config`.
826846 compressor : Codec, optional
827- Primary compressor.
828- fill_value : object
847+ Primary compressor to compress chunk data.
848+ V2 only. V3 arrays should use ``codecs`` instead.
849+
850+ If neither ``compressor`` nor ``filters`` are provided, a default compressor will be used:
851+
852+ - For numeric arrays, the default is ``ZstdCodec``.
853+ - For Unicode strings, the default is ``VLenUTF8Codec``.
854+ - For bytes or objects, the default is ``VLenBytesCodec``.
855+
856+ These defaults can be changed by modifying the value of ``array.v2_default_compressor`` in :mod:`zarr.core.config`. fill_value : object
829857 Default value to use for uninitialized portions of the array.
830858 order : {'C', 'F'}, optional
831859 Memory layout to be used within each chunk.
832- Default is set in Zarr's config (` array.order`) .
860+ If not specified, default is taken from the Zarr config ``` array.order``` .
833861 store : Store or str
834862 Store or path to directory in file system or name of zip file.
835863 synchronizer : object, optional
@@ -844,6 +872,8 @@ async def create(
844872 for storage of both chunks and metadata.
845873 filters : sequence of Codecs, optional
846874 Sequence of filters to use to encode chunk data prior to compression.
875+ V2 only. If neither ``compressor`` nor ``filters`` are provided, a default
876+ compressor will be used. (see ``compressor`` for details).
847877 cache_metadata : bool, optional
848878 If True, array configuration metadata will be cached for the
849879 lifetime of the object. If False, array metadata will be reloaded
@@ -859,7 +889,8 @@ async def create(
859889 A codec to encode object arrays, only needed if dtype=object.
860890 dimension_separator : {'.', '/'}, optional
861891 Separator placed between the dimensions of a chunk.
862-
892+ V2 only. V3 arrays should use ``chunk_key_encoding`` instead.
893+ Default is ".".
863894 .. versionadded:: 2.8
864895
865896 write_empty_chunks : bool, optional
@@ -875,6 +906,7 @@ async def create(
875906
876907 zarr_format : {2, 3, None}, optional
877908 The zarr format to use when saving.
909+ Default is 3.
878910 meta_array : array-like, optional
879911 An array instance to use for determining arrays to create and return
880912 to users. Use `numpy.empty(())` by default.
@@ -894,9 +926,13 @@ async def create(
894926 or _default_zarr_version ()
895927 )
896928
897- if zarr_format == 2 and chunks is None :
898- chunks = shape
899- elif zarr_format == 3 and chunk_shape is None :
929+ if zarr_format == 2 :
930+ if chunks is None :
931+ chunks = shape
932+ dtype = parse_dtype (dtype , zarr_format )
933+ if not filters and not compressor :
934+ filters , compressor = _default_filters_and_compressor (dtype )
935+ elif zarr_format == 3 and chunk_shape is None : # type: ignore[redundant-expr]
900936 if chunks is not None :
901937 chunk_shape = chunks
902938 chunks = None
0 commit comments