Skip to content

Commit 27abff2

Browse files
authored
Widen ChunksLike type alias (zarr-developers#3990)
* Widen ChunksLike type alias Fixes zarr-developers#3869 * Add changelog file. * Prefer if/else statement to if/else expression
1 parent 6ebc031 commit 27abff2

3 files changed

Lines changed: 12 additions & 12 deletions

File tree

changes/3990.misc.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Widen `ChunksLike` type alias to use `Iterable` instead of `Sequence`, and also
2+
remove `None` from the type union. This supports a broader range of types,
3+
removing the necessity to "materialize" iterable values simply to satisfy type
4+
annotations. It also allows use of `ChunksLike` in cases where `None` should
5+
not be permitted.

src/zarr/core/array.py

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4397,11 +4397,8 @@ async def init_array(
43974397
chunk_key_encoding, zarr_format=zarr_format
43984398
)
43994399

4400-
if overwrite:
4401-
if store_path.store.supports_deletes:
4402-
await store_path.delete_dir()
4403-
else:
4404-
await ensure_no_existing_node(store_path, zarr_format=zarr_format)
4400+
if overwrite and store_path.store.supports_deletes:
4401+
await store_path.delete_dir()
44054402
else:
44064403
await ensure_no_existing_node(store_path, zarr_format=zarr_format)
44074404

@@ -4417,12 +4414,10 @@ async def init_array(
44174414
)
44184415

44194416
# Normalize the user's chunks into canonical ChunksTuple form
4420-
if chunks is None or chunks == "auto":
4421-
chunks_normalized = guess_chunks(
4422-
shape_parsed,
4423-
item_size,
4424-
max_bytes=SHARDED_INNER_CHUNK_MAX_BYTES if shards is not None else None,
4425-
)
4417+
4418+
if chunks == "auto":
4419+
max_bytes = None if shards is None else SHARDED_INNER_CHUNK_MAX_BYTES
4420+
chunks_normalized = guess_chunks(shape_parsed, item_size, max_bytes=max_bytes)
44264421
else:
44274422
chunks_normalized = normalize_chunks_nd(chunks, shape_parsed)
44284423

src/zarr/core/common.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737

3838
BytesLike = bytes | bytearray | memoryview
3939
ShapeLike = Iterable[int | np.integer[Any]] | int | np.integer[Any]
40-
ChunksLike = ShapeLike | Sequence[Sequence[int]] | None
40+
ChunksLike = ShapeLike | Iterable[Iterable[int]]
4141
# For backwards compatibility
4242
ChunkCoords = tuple[int, ...]
4343
ZarrFormat = Literal[2, 3]

0 commit comments

Comments
 (0)