Skip to content

Commit 15ec284

Browse files
committed
Merge branch 'main' into return-scalar-for-zero-dim-indexing
# Conflicts: # tests/test_array.py
2 parents 2aca6c2 + fc08f31 commit 15ec284

File tree

7 files changed

+444
-106
lines changed

7 files changed

+444
-106
lines changed

changes/2761.feature.1.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Adds a new function ``init_array`` for initializing an array in storage, and refactors ``create_array``
2+
to use ``init_array``. ``create_array`` takes two a new parameters: ``data``, an optional array-like object, and ``write_data``, a bool which defaults to ``True``.
3+
If ``data`` is given to ``create_array``, then the ``dtype`` and ``shape`` attributes of ``data`` are used to define the
4+
corresponding attributes of the resulting Zarr array. Additionally, if ``data`` given and ``write_data`` is ``True``,
5+
then the values in ``data`` will be written to the newly created array.

changes/2763.chore.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Created a type alias ``ChunkKeyEncodingLike`` to model the union of ``ChunkKeyEncoding`` instances and the dict form of the
2+
parameters of those instances. ``ChunkKeyEncodingLike`` should be used by high-level functions to provide a convenient
3+
way for creating ``ChunkKeyEncoding`` objects.

src/zarr/api/synchronous.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
if TYPE_CHECKING:
1515
from collections.abc import Iterable
1616

17+
import numpy as np
1718
import numpy.typing as npt
1819

1920
from zarr.abc.codec import Codec
@@ -744,8 +745,9 @@ def create_array(
744745
store: str | StoreLike,
745746
*,
746747
name: str | None = None,
747-
shape: ShapeLike,
748-
dtype: npt.DTypeLike,
748+
shape: ShapeLike | None = None,
749+
dtype: npt.DTypeLike | None = None,
750+
data: np.ndarray[Any, np.dtype[Any]] | None = None,
749751
chunks: ChunkCoords | Literal["auto"] = "auto",
750752
shards: ShardsLike | None = None,
751753
filters: FiltersLike = "auto",
@@ -772,10 +774,14 @@ def create_array(
772774
name : str or None, optional
773775
The name of the array within the store. If ``name`` is ``None``, the array will be located
774776
at the root of the store.
775-
shape : ChunkCoords
776-
Shape of the array.
777-
dtype : npt.DTypeLike
778-
Data type of the array.
777+
shape : ChunkCoords, optional
778+
Shape of the array. Can be ``None`` if ``data`` is provided.
779+
dtype : npt.DTypeLike, optional
780+
Data type of the array. Can be ``None`` if ``data`` is provided.
781+
data : np.ndarray, optional
782+
Array-like data to use for initializing the array. If this parameter is provided, the
783+
``shape`` and ``dtype`` parameters must be identical to ``data.shape`` and ``data.dtype``,
784+
or ``None``.
779785
chunks : ChunkCoords, optional
780786
Chunk shape of the array.
781787
If not specified, default are guessed based on the shape and dtype.
@@ -874,6 +880,7 @@ def create_array(
874880
name=name,
875881
shape=shape,
876882
dtype=dtype,
883+
data=data,
877884
chunks=chunks,
878885
shards=shards,
879886
filters=filters,

0 commit comments

Comments
 (0)