10
10
from typing_extensions import deprecated
11
11
12
12
from zarr .core .array import Array , AsyncArray , get_array_metadata
13
+ from zarr .core .array_spec import ArrayConfig , ArrayConfigParams
13
14
from zarr .core .buffer import NDArrayLike
14
15
from zarr .core .common import (
15
16
JSON ,
16
17
AccessModeLiteral ,
17
18
ChunkCoords ,
18
19
MemoryOrder ,
19
20
ZarrFormat ,
21
+ _warn_order_kwarg ,
22
+ _warn_write_empty_chunks_kwarg ,
20
23
parse_dtype ,
21
24
)
22
25
from zarr .core .config import config
@@ -794,7 +797,7 @@ async def create(
794
797
read_only : bool | None = None ,
795
798
object_codec : Codec | None = None , # TODO: type has changed
796
799
dimension_separator : Literal ["." , "/" ] | None = None ,
797
- write_empty_chunks : bool = False , # TODO: default has changed
800
+ write_empty_chunks : bool | None = None ,
798
801
zarr_version : ZarrFormat | None = None , # deprecated
799
802
zarr_format : ZarrFormat | None = None ,
800
803
meta_array : Any | None = None , # TODO: need type
@@ -810,6 +813,7 @@ async def create(
810
813
codecs : Iterable [Codec | dict [str , JSON ]] | None = None ,
811
814
dimension_names : Iterable [str ] | None = None ,
812
815
storage_options : dict [str , Any ] | None = None ,
816
+ config : ArrayConfig | ArrayConfigParams | None = None ,
813
817
** kwargs : Any ,
814
818
) -> AsyncArray [ArrayV2Metadata ] | AsyncArray [ArrayV3Metadata ]:
815
819
"""Create an array.
@@ -856,8 +860,10 @@ async def create(
856
860
These defaults can be changed by modifying the value of ``array.v2_default_compressor`` in :mod:`zarr.core.config`. fill_value : object
857
861
Default value to use for uninitialized portions of the array.
858
862
order : {'C', 'F'}, optional
863
+ Deprecated in favor of the ``config`` keyword argument.
864
+ Pass ``{'order': <value>}`` to ``create`` instead of using this parameter.
859
865
Memory layout to be used within each chunk.
860
- If not specified, default is taken from the Zarr config ``` array.order``` .
866
+ If not specified, the `` array.order`` parameter in the global config will be used .
861
867
store : Store or str
862
868
Store or path to directory in file system or name of zip file.
863
869
synchronizer : object, optional
@@ -891,30 +897,26 @@ async def create(
891
897
Separator placed between the dimensions of a chunk.
892
898
V2 only. V3 arrays should use ``chunk_key_encoding`` instead.
893
899
Default is ".".
894
- .. versionadded:: 2.8
895
-
896
900
write_empty_chunks : bool, optional
897
- If True (default), all chunks will be stored regardless of their
901
+ Deprecated in favor of the ``config`` keyword argument.
902
+ Pass ``{'write_empty_chunks': <value>}`` to ``create`` instead of using this parameter.
903
+ If True, all chunks will be stored regardless of their
898
904
contents. If False, each chunk is compared to the array's fill value
899
905
prior to storing. If a chunk is uniformly equal to the fill value, then
900
906
that chunk is not be stored, and the store entry for that chunk's key
901
- is deleted. This setting enables sparser storage, as only chunks with
902
- non-fill-value data are stored, at the expense of overhead associated
903
- with checking the data of each chunk.
904
-
905
- .. versionadded:: 2.11
906
-
907
+ is deleted.
907
908
zarr_format : {2, 3, None}, optional
908
909
The zarr format to use when saving.
909
910
Default is 3.
910
911
meta_array : array-like, optional
911
912
An array instance to use for determining arrays to create and return
912
913
to users. Use `numpy.empty(())` by default.
913
-
914
- .. versionadded:: 2.13
915
914
storage_options : dict
916
915
If using an fsspec URL to create the store, these will be passed to
917
916
the backend implementation. Ignored otherwise.
917
+ config : ArrayConfig or ArrayConfigParams, optional
918
+ Runtime configuration of the array. If provided, will override the
919
+ default values from `zarr.config.array`.
918
920
919
921
Returns
920
922
-------
@@ -951,26 +953,47 @@ async def create(
951
953
warnings .warn ("object_codec is not yet implemented" , RuntimeWarning , stacklevel = 2 )
952
954
if read_only is not None :
953
955
warnings .warn ("read_only is not yet implemented" , RuntimeWarning , stacklevel = 2 )
954
- if dimension_separator is not None :
955
- if zarr_format == 3 :
956
- raise ValueError (
957
- "dimension_separator is not supported for zarr format 3, use chunk_key_encoding instead"
958
- )
959
- else :
960
- warnings .warn (
961
- "dimension_separator is not yet implemented" ,
962
- RuntimeWarning ,
963
- stacklevel = 2 ,
964
- )
965
- if write_empty_chunks :
966
- warnings .warn ("write_empty_chunks is not yet implemented" , RuntimeWarning , stacklevel = 2 )
956
+ if dimension_separator is not None and zarr_format == 3 :
957
+ raise ValueError (
958
+ "dimension_separator is not supported for zarr format 3, use chunk_key_encoding instead"
959
+ )
960
+
961
+ if order is not None :
962
+ _warn_order_kwarg ()
963
+ if write_empty_chunks is not None :
964
+ _warn_write_empty_chunks_kwarg ()
965
+
967
966
if meta_array is not None :
968
967
warnings .warn ("meta_array is not yet implemented" , RuntimeWarning , stacklevel = 2 )
969
968
970
969
mode = kwargs .pop ("mode" , None )
971
970
if mode is None :
972
971
mode = "a"
973
972
store_path = await make_store_path (store , path = path , mode = mode , storage_options = storage_options )
973
+
974
+ config_dict : ArrayConfigParams = {}
975
+
976
+ if write_empty_chunks is not None :
977
+ if config is not None :
978
+ msg = (
979
+ "Both write_empty_chunks and config keyword arguments are set. "
980
+ "This is redundant. When both are set, write_empty_chunks will be ignored and "
981
+ "config will be used."
982
+ )
983
+ warnings .warn (UserWarning (msg ), stacklevel = 1 )
984
+ config_dict ["write_empty_chunks" ] = write_empty_chunks
985
+ if order is not None :
986
+ if config is not None :
987
+ msg = (
988
+ "Both order and config keyword arguments are set. "
989
+ "This is redundant. When both are set, order will be ignored and "
990
+ "config will be used."
991
+ )
992
+ warnings .warn (UserWarning (msg ), stacklevel = 1 )
993
+ config_dict ["order" ] = order
994
+
995
+ config_parsed = ArrayConfig .from_dict (config_dict )
996
+
974
997
return await AsyncArray .create (
975
998
store_path ,
976
999
shape = shape ,
@@ -987,7 +1010,7 @@ async def create(
987
1010
codecs = codecs ,
988
1011
dimension_names = dimension_names ,
989
1012
attributes = attributes ,
990
- order = order ,
1013
+ config = config_parsed ,
991
1014
** kwargs ,
992
1015
)
993
1016
@@ -1163,6 +1186,11 @@ async def open_array(
1163
1186
1164
1187
zarr_format = _handle_zarr_version_or_format (zarr_version = zarr_version , zarr_format = zarr_format )
1165
1188
1189
+ if "order" in kwargs :
1190
+ _warn_order_kwarg ()
1191
+ if "write_empty_chunks" in kwargs :
1192
+ _warn_write_empty_chunks_kwarg ()
1193
+
1166
1194
try :
1167
1195
return await AsyncArray .open (store_path , zarr_format = zarr_format )
1168
1196
except FileNotFoundError :
0 commit comments