Skip to content

Commit 210f4e9

Browse files
committed
add signature tests for async / sync api, and fix mismatched signatures
1 parent c66f32b commit 210f4e9

File tree

3 files changed

+34
-2
lines changed

3 files changed

+34
-2
lines changed

src/zarr/api/asynchronous.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -824,7 +824,7 @@ async def open_group(
824824
async def create(
825825
shape: ChunkCoords | int,
826826
*, # Note: this is a change from v2
827-
chunks: ChunkCoords | int | None = None, # TODO: v2 allowed chunks=True
827+
chunks: ChunkCoords | int | bool | None = None,
828828
dtype: npt.DTypeLike | None = None,
829829
compressor: dict[str, JSON] | None = None, # TODO: default and type change
830830
fill_value: Any | None = 0, # TODO: need type

src/zarr/api/synchronous.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -757,11 +757,12 @@ def create_array(
757757
order: MemoryOrder | None = None,
758758
zarr_format: ZarrFormat | None = 3,
759759
attributes: dict[str, JSON] | None = None,
760-
chunk_key_encoding: ChunkKeyEncoding | ChunkKeyEncodingLike | None = None,
760+
chunk_key_encoding: ChunkKeyEncodingLike | None = None,
761761
dimension_names: Iterable[str] | None = None,
762762
storage_options: dict[str, Any] | None = None,
763763
overwrite: bool = False,
764764
config: ArrayConfig | ArrayConfigLike | None = None,
765+
write_data: bool = True,
765766
) -> Array:
766767
"""Create an array.
767768
@@ -855,6 +856,11 @@ def create_array(
855856
Whether to overwrite an array with the same name in the store, if one exists.
856857
config : ArrayConfig or ArrayConfigLike, optional
857858
Runtime configuration for the array.
859+
write_data : bool
860+
If a pre-existing array-like object was provided to this function via the ``data`` parameter
861+
then ``write_data`` determines whether the values in that array-like object should be
862+
written to the Zarr array created by this function. If ``write_data`` is ``False``, then the
863+
array will be left empty.
858864
859865
Returns
860866
-------
@@ -895,6 +901,7 @@ def create_array(
895901
storage_options=storage_options,
896902
overwrite=overwrite,
897903
config=config,
904+
write_data=write_data,
898905
)
899906
)
900907
)

tests/test_api.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
import inspect
12
import pathlib
23
import warnings
4+
from collections.abc import Callable
35
from typing import Literal
46

57
import numpy as np
@@ -8,6 +10,7 @@
810

911
import zarr
1012
import zarr.api.asynchronous
13+
import zarr.api.synchronous
1114
import zarr.core.group
1215
from zarr import Array, Group
1316
from zarr.abc.store import Store
@@ -1121,3 +1124,25 @@ def test_open_array_with_mode_r_plus(store: Store) -> None:
11211124
assert isinstance(z2, Array)
11221125
assert (z2[:] == 1).all()
11231126
z2[:] = 3
1127+
1128+
1129+
@pytest.mark.parametrize(
1130+
("a_func", "b_func"),
1131+
[
1132+
(zarr.api.asynchronous.create_array, zarr.api.synchronous.create_array),
1133+
(zarr.api.asynchronous.save, zarr.api.synchronous.save),
1134+
(zarr.api.asynchronous.save_array, zarr.api.synchronous.save_array),
1135+
(zarr.api.asynchronous.save_group, zarr.api.synchronous.save_group),
1136+
(zarr.api.asynchronous.open_group, zarr.api.synchronous.open_group),
1137+
(zarr.api.asynchronous.create, zarr.api.synchronous.create),
1138+
],
1139+
)
1140+
def test_consistent_signatures(
1141+
a_func: Callable[[object], object], b_func: Callable[[object], object]
1142+
) -> None:
1143+
"""
1144+
Ensure that pairs of functions have the same signature
1145+
"""
1146+
base_sig = inspect.signature(a_func)
1147+
test_sig = inspect.signature(b_func)
1148+
assert test_sig.parameters == base_sig.parameters

0 commit comments

Comments
 (0)