Skip to content

Commit

Permalink
Allow 'chunks' as an alias for 'chunk_shape' in array creation. (zarr…
Browse files Browse the repository at this point in the history
  • Loading branch information
tomwhite authored Jun 25, 2024
1 parent c677da4 commit 5a4a50f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/zarr/api/asynchronous.py
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,11 @@ async def create(
if zarr_format == 2 and chunks is None:
chunks = shape
if zarr_format == 3 and chunk_shape is None:
chunk_shape = shape
if chunks is not None:
chunk_shape = chunks
chunks = None
else:
chunk_shape = shape

if order is not None:
warnings.warn(
Expand Down
23 changes: 22 additions & 1 deletion tests/v3/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,28 @@
import zarr
from zarr import Array, Group
from zarr.abc.store import Store
from zarr.api.synchronous import load, open, open_group, save, save_array, save_group
from zarr.api.synchronous import create, load, open, open_group, save, save_array, save_group


def test_create_array(memory_store: Store) -> None:
store = memory_store

# create array
z = create(shape=100, store=store)
assert isinstance(z, Array)
assert z.shape == (100,)

# create array, overwrite, specify chunk shape
z = create(shape=200, chunk_shape=20, store=store, overwrite=True)
assert isinstance(z, Array)
assert z.shape == (200,)
assert z.chunks == (20,)

# create array, overwrite, specify chunk shape via chunks param
z = create(shape=400, chunks=40, store=store, overwrite=True)
assert isinstance(z, Array)
assert z.shape == (400,)
assert z.chunks == (40,)


def test_open_array(memory_store: Store) -> None:
Expand Down

0 comments on commit 5a4a50f

Please sign in to comment.