Skip to content

Commit 06a9288

Browse files
committed
Merge branch 'v3' into hypothesis-tests
* v3: Allow 'chunks' as an alias for 'chunk_shape' in array creation. (zarr-developers#1991)
2 parents 35ba251 + 5a4a50f commit 06a9288

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

src/zarr/api/asynchronous.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -646,7 +646,11 @@ async def create(
646646
if zarr_format == 2 and chunks is None:
647647
chunks = shape
648648
if zarr_format == 3 and chunk_shape is None:
649-
chunk_shape = shape
649+
if chunks is not None:
650+
chunk_shape = chunks
651+
chunks = None
652+
else:
653+
chunk_shape = shape
650654

651655
if order is not None:
652656
warnings.warn(

tests/v3/test_api.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,28 @@
55
import zarr
66
from zarr import Array, Group
77
from zarr.abc.store import Store
8-
from zarr.api.synchronous import load, open, open_group, save, save_array, save_group
8+
from zarr.api.synchronous import create, load, open, open_group, save, save_array, save_group
9+
10+
11+
def test_create_array(memory_store: Store) -> None:
12+
store = memory_store
13+
14+
# create array
15+
z = create(shape=100, store=store)
16+
assert isinstance(z, Array)
17+
assert z.shape == (100,)
18+
19+
# create array, overwrite, specify chunk shape
20+
z = create(shape=200, chunk_shape=20, store=store, overwrite=True)
21+
assert isinstance(z, Array)
22+
assert z.shape == (200,)
23+
assert z.chunks == (20,)
24+
25+
# create array, overwrite, specify chunk shape via chunks param
26+
z = create(shape=400, chunks=40, store=store, overwrite=True)
27+
assert isinstance(z, Array)
28+
assert z.shape == (400,)
29+
assert z.chunks == (40,)
930

1031

1132
def test_open_array(memory_store: Store) -> None:

0 commit comments

Comments
 (0)