Skip to content

Commit 665eebb

Browse files
committed
test for async group / group methods
1 parent 4c966c0 commit 665eebb

File tree

2 files changed

+38
-8
lines changed

2 files changed

+38
-8
lines changed

src/zarr/core/group.py

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2249,22 +2249,24 @@ def create_array(
22492249
self,
22502250
name: str,
22512251
*,
2252-
shape: ShapeLike,
2253-
dtype: npt.DTypeLike,
2252+
shape: ShapeLike | None = None,
2253+
dtype: npt.DTypeLike | None = None,
2254+
data: np.ndarray[Any, np.dtype[Any]] | None = None,
22542255
chunks: ChunkCoords | Literal["auto"] = "auto",
22552256
shards: ShardsLike | None = None,
22562257
filters: FiltersLike = "auto",
22572258
compressors: CompressorsLike = "auto",
22582259
compressor: CompressorLike = "auto",
22592260
serializer: SerializerLike = "auto",
22602261
fill_value: Any | None = 0,
2261-
order: MemoryOrder | None = "C",
2262+
order: MemoryOrder | None = None,
22622263
attributes: dict[str, JSON] | None = None,
2263-
chunk_key_encoding: ChunkKeyEncoding | ChunkKeyEncodingLike | None = None,
2264+
chunk_key_encoding: ChunkKeyEncodingLike | None = None,
22642265
dimension_names: Iterable[str] | None = None,
22652266
storage_options: dict[str, Any] | None = None,
22662267
overwrite: bool = False,
22672268
config: ArrayConfig | ArrayConfigLike | None = None,
2269+
write_data: bool = True,
22682270
) -> Array:
22692271
"""Create an array within this group.
22702272
@@ -2275,10 +2277,13 @@ def create_array(
22752277
name : str
22762278
The name of the array relative to the group. If ``path`` is ``None``, the array will be located
22772279
at the root of the store.
2278-
shape : ChunkCoords
2279-
Shape of the array.
2280-
dtype : npt.DTypeLike
2281-
Data type of the array.
2280+
shape : ChunkCoords, optional
2281+
Shape of the array. Can be ``None`` if ``data`` is provided.
2282+
dtype : npt.DTypeLike | None
2283+
Data type of the array. Can be ``None`` if ``data`` is provided.
2284+
data : Array-like data to use for initializing the array. If this parameter is provided, the
2285+
``shape`` and ``dtype`` parameters must be identical to ``data.shape`` and ``data.dtype``,
2286+
or ``None``.
22822287
chunks : ChunkCoords, optional
22832288
Chunk shape of the array.
22842289
If not specified, default are guessed based on the shape and dtype.
@@ -2352,6 +2357,11 @@ def create_array(
23522357
Whether to overwrite an array with the same name in the store, if one exists.
23532358
config : ArrayConfig or ArrayConfigLike, optional
23542359
Runtime configuration for the array.
2360+
write_data : bool
2361+
If a pre-existing array-like object was provided to this function via the ``data`` parameter
2362+
then ``write_data`` determines whether the values in that array-like object should be
2363+
written to the Zarr array created by this function. If ``write_data`` is ``False``, then the
2364+
array will be left empty.
23552365
23562366
Returns
23572367
-------
@@ -2366,6 +2376,7 @@ def create_array(
23662376
name=name,
23672377
shape=shape,
23682378
dtype=dtype,
2379+
data=data,
23692380
chunks=chunks,
23702381
shards=shards,
23712382
fill_value=fill_value,
@@ -2379,6 +2390,7 @@ def create_array(
23792390
overwrite=overwrite,
23802391
storage_options=storage_options,
23812392
config=config,
2393+
write_data=write_data,
23822394
)
23832395
)
23842396
)

tests/test_group.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import annotations
22

33
import contextlib
4+
import inspect
45
import operator
56
import pickle
67
import time
@@ -29,6 +30,8 @@
2930
from .conftest import parse_store
3031

3132
if TYPE_CHECKING:
33+
from collections.abc import Callable
34+
3235
from _pytest.compat import LEGACY_PATH
3336

3437
from zarr.core.common import JSON, ZarrFormat
@@ -1505,3 +1508,18 @@ def test_group_members_concurrency_limit(store: MemoryStore) -> None:
15051508
elapsed = time.time() - start
15061509

15071510
assert elapsed > num_groups * get_latency
1511+
1512+
1513+
@pytest.mark.parametrize(
1514+
("a_func", "b_func"),
1515+
[(zarr.core.group.AsyncGroup.create_array, zarr.core.group.Group.create_array)],
1516+
)
1517+
def test_consistent_signatures(
1518+
a_func: Callable[[object], object], b_func: Callable[[object], object]
1519+
) -> None:
1520+
"""
1521+
Ensure that pairs of functions have consistent signatures
1522+
"""
1523+
base_sig = inspect.signature(a_func)
1524+
test_sig = inspect.signature(b_func)
1525+
assert test_sig.parameters == base_sig.parameters

0 commit comments

Comments
 (0)