1010from typing_extensions import deprecated
1111
1212from zarr .core .array import Array , AsyncArray , get_array_metadata
13+ from zarr .core .array_spec import ArrayConfig , ArrayConfigParams
1314from zarr .core .buffer import NDArrayLike
1415from zarr .core .common import (
1516 JSON ,
1617 AccessModeLiteral ,
1718 ChunkCoords ,
1819 MemoryOrder ,
1920 ZarrFormat ,
21+ _warn_order_kwarg ,
22+ _warn_write_empty_chunks_kwarg ,
2023 parse_dtype ,
2124)
2225from zarr .core .config import config
@@ -575,7 +578,7 @@ async def array(
575578 z = await create (** kwargs )
576579
577580 # fill with data
578- await z .setitem (slice ( None ) , data )
581+ await z .setitem (Ellipsis , data )
579582
580583 return z
581584
@@ -793,7 +796,7 @@ async def create(
793796 read_only : bool | None = None ,
794797 object_codec : Codec | None = None , # TODO: type has changed
795798 dimension_separator : Literal ["." , "/" ] | None = None ,
796- write_empty_chunks : bool = False , # TODO: default has changed
799+ write_empty_chunks : bool | None = None ,
797800 zarr_version : ZarrFormat | None = None , # deprecated
798801 zarr_format : ZarrFormat | None = None ,
799802 meta_array : Any | None = None , # TODO: need type
@@ -809,6 +812,7 @@ async def create(
809812 codecs : Iterable [Codec | dict [str , JSON ]] | None = None ,
810813 dimension_names : Iterable [str ] | None = None ,
811814 storage_options : dict [str , Any ] | None = None ,
815+ config : ArrayConfig | ArrayConfigParams | None = None ,
812816 ** kwargs : Any ,
813817) -> AsyncArray [ArrayV2Metadata ] | AsyncArray [ArrayV3Metadata ]:
814818 """Create an array.
@@ -855,8 +859,10 @@ async def create(
855859 These defaults can be changed by modifying the value of ``array.v2_default_compressor`` in :mod:`zarr.core.config`. fill_value : object
856860 Default value to use for uninitialized portions of the array.
857861 order : {'C', 'F'}, optional
862+ Deprecated in favor of the ``config`` keyword argument.
863+ Pass ``{'order': <value>}`` to ``create`` instead of using this parameter.
858864 Memory layout to be used within each chunk.
859- If not specified, default is taken from the Zarr config ``` array.order``` .
865+ If not specified, the `` array.order`` parameter in the global config will be used .
860866 store : Store or str
861867 Store or path to directory in file system or name of zip file.
862868 synchronizer : object, optional
@@ -890,30 +896,26 @@ async def create(
890896 Separator placed between the dimensions of a chunk.
891897 V2 only. V3 arrays should use ``chunk_key_encoding`` instead.
892898 Default is ".".
893- .. versionadded:: 2.8
894-
895899 write_empty_chunks : bool, optional
896- If True (default), all chunks will be stored regardless of their
900+ Deprecated in favor of the ``config`` keyword argument.
901+ Pass ``{'write_empty_chunks': <value>}`` to ``create`` instead of using this parameter.
902+ If True, all chunks will be stored regardless of their
897903 contents. If False, each chunk is compared to the array's fill value
898904 prior to storing. If a chunk is uniformly equal to the fill value, then
899905 that chunk is not be stored, and the store entry for that chunk's key
900- is deleted. This setting enables sparser storage, as only chunks with
901- non-fill-value data are stored, at the expense of overhead associated
902- with checking the data of each chunk.
903-
904- .. versionadded:: 2.11
905-
906+ is deleted.
906907 zarr_format : {2, 3, None}, optional
907908 The zarr format to use when saving.
908909 Default is 3.
909910 meta_array : array-like, optional
910911 An array instance to use for determining arrays to create and return
911912 to users. Use `numpy.empty(())` by default.
912-
913- .. versionadded:: 2.13
914913 storage_options : dict
915914 If using an fsspec URL to create the store, these will be passed to
916915 the backend implementation. Ignored otherwise.
916+ config : ArrayConfig or ArrayConfigParams, optional
917+ Runtime configuration of the array. If provided, will override the
918+ default values from `zarr.config.array`.
917919
918920 Returns
919921 -------
@@ -950,26 +952,47 @@ async def create(
950952 warnings .warn ("object_codec is not yet implemented" , RuntimeWarning , stacklevel = 2 )
951953 if read_only is not None :
952954 warnings .warn ("read_only is not yet implemented" , RuntimeWarning , stacklevel = 2 )
953- if dimension_separator is not None :
954- if zarr_format == 3 :
955- raise ValueError (
956- "dimension_separator is not supported for zarr format 3, use chunk_key_encoding instead"
957- )
958- else :
959- warnings .warn (
960- "dimension_separator is not yet implemented" ,
961- RuntimeWarning ,
962- stacklevel = 2 ,
963- )
964- if write_empty_chunks :
965- warnings .warn ("write_empty_chunks is not yet implemented" , RuntimeWarning , stacklevel = 2 )
955+ if dimension_separator is not None and zarr_format == 3 :
956+ raise ValueError (
957+ "dimension_separator is not supported for zarr format 3, use chunk_key_encoding instead"
958+ )
959+
960+ if order is not None :
961+ _warn_order_kwarg ()
962+ if write_empty_chunks is not None :
963+ _warn_write_empty_chunks_kwarg ()
964+
966965 if meta_array is not None :
967966 warnings .warn ("meta_array is not yet implemented" , RuntimeWarning , stacklevel = 2 )
968967
969968 mode = kwargs .pop ("mode" , None )
970969 if mode is None :
971970 mode = "a"
972971 store_path = await make_store_path (store , path = path , mode = mode , storage_options = storage_options )
972+
973+ config_dict : ArrayConfigParams = {}
974+
975+ if write_empty_chunks is not None :
976+ if config is not None :
977+ msg = (
978+ "Both write_empty_chunks and config keyword arguments are set. "
979+ "This is redundant. When both are set, write_empty_chunks will be ignored and "
980+ "config will be used."
981+ )
982+ warnings .warn (UserWarning (msg ), stacklevel = 1 )
983+ config_dict ["write_empty_chunks" ] = write_empty_chunks
984+ if order is not None :
985+ if config is not None :
986+ msg = (
987+ "Both order and config keyword arguments are set. "
988+ "This is redundant. When both are set, order will be ignored and "
989+ "config will be used."
990+ )
991+ warnings .warn (UserWarning (msg ), stacklevel = 1 )
992+ config_dict ["order" ] = order
993+
994+ config_parsed = ArrayConfig .from_dict (config_dict )
995+
973996 return await AsyncArray .create (
974997 store_path ,
975998 shape = shape ,
@@ -986,7 +1009,7 @@ async def create(
9861009 codecs = codecs ,
9871010 dimension_names = dimension_names ,
9881011 attributes = attributes ,
989- order = order ,
1012+ config = config_parsed ,
9901013 ** kwargs ,
9911014 )
9921015
@@ -1162,6 +1185,11 @@ async def open_array(
11621185
11631186 zarr_format = _handle_zarr_version_or_format (zarr_version = zarr_version , zarr_format = zarr_format )
11641187
1188+ if "order" in kwargs :
1189+ _warn_order_kwarg ()
1190+ if "write_empty_chunks" in kwargs :
1191+ _warn_write_empty_chunks_kwarg ()
1192+
11651193 try :
11661194 return await AsyncArray .open (store_path , zarr_format = zarr_format )
11671195 except FileNotFoundError :
0 commit comments