Skip to content

Commit d920a9d

Browse files
committed
Merge branch 'main' of https://github.com/zarr-developers/zarr-python into feat/concurrent-members
2 parents 3f8de76 + 190b867 commit d920a9d

File tree

17 files changed

+409
-161
lines changed

17 files changed

+409
-161
lines changed

README-v3.md

Lines changed: 0 additions & 49 deletions
This file was deleted.

src/zarr/api/asynchronous.py

Lines changed: 56 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,16 @@
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,
1617
AccessModeLiteral,
1718
ChunkCoords,
1819
MemoryOrder,
1920
ZarrFormat,
21+
_warn_order_kwarg,
22+
_warn_write_empty_chunks_kwarg,
2023
parse_dtype,
2124
)
2225
from 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:

src/zarr/api/synchronous.py

Lines changed: 14 additions & 14 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
@@ -542,7 +543,7 @@ def create(
542543
read_only: bool | None = None,
543544
object_codec: Codec | None = None, # TODO: type has changed
544545
dimension_separator: Literal[".", "/"] | None = None,
545-
write_empty_chunks: bool = False, # TODO: default has changed
546+
write_empty_chunks: bool | None = None, # TODO: default has changed
546547
zarr_version: ZarrFormat | None = None, # deprecated
547548
zarr_format: ZarrFormat | None = None,
548549
meta_array: Any | None = None, # TODO: need type
@@ -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
)

src/zarr/codecs/sharding.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
from zarr.abc.store import ByteGetter, ByteRangeRequest, ByteSetter
2121
from zarr.codecs.bytes import BytesCodec
2222
from zarr.codecs.crc32c_ import Crc32cCodec
23-
from zarr.core.array_spec import ArraySpec
23+
from zarr.core.array_spec import ArrayConfig, ArraySpec
2424
from zarr.core.buffer import (
2525
Buffer,
2626
BufferPrototype,
@@ -665,7 +665,9 @@ def _get_index_chunk_spec(self, chunks_per_shard: ChunkCoords) -> ArraySpec:
665665
shape=chunks_per_shard + (2,),
666666
dtype=np.dtype("<u8"),
667667
fill_value=MAX_UINT_64,
668-
order="C", # Note: this is hard-coded for simplicity -- it is not surfaced into user code
668+
config=ArrayConfig(
669+
order="C", write_empty_chunks=False
670+
), # Note: this is hard-coded for simplicity -- it is not surfaced into user code,
669671
prototype=numpy_buffer_prototype(),
670672
)
671673

@@ -674,7 +676,7 @@ def _get_chunk_spec(self, shard_spec: ArraySpec) -> ArraySpec:
674676
shape=self.chunk_shape,
675677
dtype=shard_spec.dtype,
676678
fill_value=shard_spec.fill_value,
677-
order=shard_spec.order,
679+
config=shard_spec.config,
678680
prototype=shard_spec.prototype,
679681
)
680682

src/zarr/codecs/transpose.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def resolve_metadata(self, chunk_spec: ArraySpec) -> ArraySpec:
8484
shape=tuple(chunk_spec.shape[self.order[i]] for i in range(chunk_spec.ndim)),
8585
dtype=chunk_spec.dtype,
8686
fill_value=chunk_spec.fill_value,
87-
order=chunk_spec.order,
87+
config=chunk_spec.config,
8888
prototype=chunk_spec.prototype,
8989
)
9090

0 commit comments

Comments
 (0)