Skip to content

Commit 0b6e7d8

Browse files
committed
remove write_empty_chunks from Array.create; separate metadata order from config order
1 parent ca21289 commit 0b6e7d8

File tree

7 files changed

+187
-99
lines changed

7 files changed

+187
-99
lines changed

src/zarr/api/asynchronous.py

Lines changed: 37 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from typing_extensions import deprecated
1111

1212
from zarr.core.array import Array, AsyncArray, get_array_metadata
13+
from zarr.core.array_spec import ArrayConfig, ArrayConfigParams
1314
from zarr.core.buffer import NDArrayLike
1415
from zarr.core.common import (
1516
JSON,
@@ -812,6 +813,7 @@ async def create(
812813
codecs: Iterable[Codec | dict[str, JSON]] | None = None,
813814
dimension_names: Iterable[str] | None = None,
814815
storage_options: dict[str, Any] | None = None,
816+
config: ArrayConfig | ArrayConfigParams | None = None,
815817
**kwargs: Any,
816818
) -> AsyncArray[ArrayV2Metadata] | AsyncArray[ArrayV3Metadata]:
817819
"""Create an array.
@@ -858,9 +860,10 @@ async def create(
858860
These defaults can be changed by modifying the value of ``array.v2_default_compressor`` in :mod:`zarr.core.config`. fill_value : object
859861
Default value to use for uninitialized portions of the array.
860862
order : {'C', 'F'}, optional
861-
Deprecated in favor of the `array.order` configuration variable.
863+
Deprecated in favor of the ``config`` keyword argument.
864+
Pass ``{'order': <value>}`` to ``create`` instead of using this parameter.
862865
Memory layout to be used within each chunk.
863-
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.
864867
store : Store or str
865868
Store or path to directory in file system or name of zip file.
866869
synchronizer : object, optional
@@ -894,32 +897,26 @@ async def create(
894897
Separator placed between the dimensions of a chunk.
895898
V2 only. V3 arrays should use ``chunk_key_encoding`` instead.
896899
Default is ".".
897-
.. versionadded:: 2.8
898-
899900
write_empty_chunks : bool, optional
900-
Deprecated in favor of the `array.write_empty_chunks` configuration variable.
901-
902-
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
903904
contents. If False, each chunk is compared to the array's fill value
904905
prior to storing. If a chunk is uniformly equal to the fill value, then
905906
that chunk is not be stored, and the store entry for that chunk's key
906-
is deleted. This setting enables sparser storage, as only chunks with
907-
non-fill-value data are stored, at the expense of overhead associated
908-
with checking the data of each chunk.
909-
910-
.. versionadded:: 2.11
911-
907+
is deleted.
912908
zarr_format : {2, 3, None}, optional
913909
The zarr format to use when saving.
914910
Default is 3.
915911
meta_array : array-like, optional
916912
An array instance to use for determining arrays to create and return
917913
to users. Use `numpy.empty(())` by default.
918-
919-
.. versionadded:: 2.13
920914
storage_options : dict
921915
If using an fsspec URL to create the store, these will be passed to
922916
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`.
923920
924921
Returns
925922
-------
@@ -973,6 +970,30 @@ async def create(
973970
if mode is None:
974971
mode = "a"
975972
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+
976997
return await AsyncArray.create(
977998
store_path,
978999
shape=shape,
@@ -989,8 +1010,7 @@ async def create(
9891010
codecs=codecs,
9901011
dimension_names=dimension_names,
9911012
attributes=attributes,
992-
order=order,
993-
write_empty_chunks=write_empty_chunks,
1013+
config=config_parsed,
9941014
**kwargs,
9951015
)
9961016

src/zarr/api/synchronous.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
from zarr.abc.codec import Codec
1919
from zarr.api.asynchronous import ArrayLike, PathLike
20+
from zarr.core.array_spec import ArrayConfig, ArrayConfigParams
2021
from zarr.core.buffer import NDArrayLike
2122
from zarr.core.chunk_key_encodings import ChunkKeyEncoding
2223
from zarr.core.common import JSON, AccessModeLiteral, ChunkCoords, MemoryOrder, ZarrFormat
@@ -558,6 +559,7 @@ def create(
558559
codecs: Iterable[Codec | dict[str, JSON]] | None = None,
559560
dimension_names: Iterable[str] | None = None,
560561
storage_options: dict[str, Any] | None = None,
562+
config: ArrayConfig | ArrayConfigParams | None = None,
561563
**kwargs: Any,
562564
) -> Array:
563565
"""Create an array.
@@ -578,8 +580,10 @@ def create(
578580
fill_value : object
579581
Default value to use for uninitialized portions of the array.
580582
order : {'C', 'F'}, optional
583+
Deprecated in favor of the ``config`` keyword argument.
584+
Pass ``{'order': <value>}`` to ``create`` instead of using this parameter.
581585
Memory layout to be used within each chunk.
582-
Default is set in Zarr's config (`array.order`).
586+
If not specified, the ``array.order`` parameter in the global config will be used.
583587
store : Store or str
584588
Store or path to directory in file system or name of zip file.
585589
synchronizer : object, optional
@@ -609,30 +613,25 @@ def create(
609613
A codec to encode object arrays, only needed if dtype=object.
610614
dimension_separator : {'.', '/'}, optional
611615
Separator placed between the dimensions of a chunk.
612-
613-
.. versionadded:: 2.8
614-
615616
write_empty_chunks : bool, optional
616-
If True (default), all chunks will be stored regardless of their
617+
Deprecated in favor of the ``config`` keyword argument.
618+
Pass ``{'write_empty_chunks': <value>}`` to ``create`` instead of using this parameter.
619+
If True, all chunks will be stored regardless of their
617620
contents. If False, each chunk is compared to the array's fill value
618621
prior to storing. If a chunk is uniformly equal to the fill value, then
619622
that chunk is not be stored, and the store entry for that chunk's key
620-
is deleted. This setting enables sparser storage, as only chunks with
621-
non-fill-value data are stored, at the expense of overhead associated
622-
with checking the data of each chunk.
623-
624-
.. versionadded:: 2.11
625-
623+
is deleted.
626624
zarr_format : {2, 3, None}, optional
627625
The zarr format to use when saving.
628626
meta_array : array-like, optional
629627
An array instance to use for determining arrays to create and return
630628
to users. Use `numpy.empty(())` by default.
631-
632-
.. versionadded:: 2.13
633629
storage_options : dict
634630
If using an fsspec URL to create the store, these will be passed to
635631
the backend implementation. Ignored otherwise.
632+
config : ArrayConfig or ArrayConfigParams, optional
633+
Runtime configuration of the array. If provided, will override the
634+
default values from `zarr.config.array`.
636635
637636
Returns
638637
-------
@@ -669,6 +668,7 @@ def create(
669668
codecs=codecs,
670669
dimension_names=dimension_names,
671670
storage_options=storage_options,
671+
config=config,
672672
**kwargs,
673673
)
674674
)

0 commit comments

Comments
 (0)