Skip to content

Commit 6eab392

Browse files
committed
fixups
1 parent e116f63 commit 6eab392

File tree

3 files changed

+35
-24
lines changed

3 files changed

+35
-24
lines changed

src/zarr/core/chunk_grids.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1228,7 +1228,10 @@ def _normalize_rectilinear_chunks(
12281228
"""
12291229
# Expand RLE for each dimension
12301230
try:
1231-
chunk_shapes = tuple(_expand_run_length_encoding(dim) for dim in chunks)
1231+
chunk_shapes = tuple(
1232+
_expand_run_length_encoding(dim) # type: ignore[arg-type]
1233+
for dim in chunks
1234+
)
12321235
except (TypeError, ValueError) as e:
12331236
raise TypeError(
12341237
f"Invalid variable chunks: {chunks}. Expected nested sequence of integers "

src/zarr/testing/strategies.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -584,16 +584,24 @@ def complex_chunk_grids(draw: st.DrawFn) -> RectilinearChunkGrid:
584584

585585
else:
586586
event("using RectilinearChunkGrid (run length encoded)")
587-
repeats = st.lists(
588-
st.integers(min_value=1, max_value=20), min_size=nchunks, max_size=nchunks
589-
)
587+
# For RLE, we need to carefully control the total expanded chunks
588+
# to avoid creating arrays that are too large
589+
# Use a small number of RLE entries with small repeat counts
590+
num_rle_entries = draw(st.integers(min_value=5, max_value=20))
590591
chunk_shapes_rle = [
591-
[[c, r] for c, r in zip(draw(dim_chunks), draw(repeats), strict=True)]
592+
[
593+
[
594+
draw(st.integers(min_value=1, max_value=10)), # chunk size
595+
draw(st.integers(min_value=1, max_value=3)), # repeat count
596+
]
597+
for _ in range(num_rle_entries)
598+
]
592599
for _ in range(ndim)
593600
]
594601
# Expand RLE to explicit chunk shapes before passing to __init__
595602
chunk_shapes_expanded = [
596-
_expand_run_length_encoding(dim_rle) for dim_rle in chunk_shapes_rle
603+
_expand_run_length_encoding(dim_rle) # type: ignore[arg-type]
604+
for dim_rle in chunk_shapes_rle
597605
]
598606
return RectilinearChunkGrid(chunk_shapes=chunk_shapes_expanded)
599607

tests/test_chunk_grids/test_rectilinear.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ def test_roundtrip_with_compression() -> None:
338338
metadata = grid1.to_dict()
339339

340340
# Verify it's compressed
341-
assert metadata["configuration"]["chunk_shapes"] == [[[10, 6]], [[5, 5]]]
341+
assert metadata["configuration"]["chunk_shapes"] == [[[10, 6]], [[5, 5]]] # type: ignore[call-overload, index]
342342

343343
# Deserialize from dict
344344
grid2 = RectilinearChunkGrid._from_dict(metadata)
@@ -396,7 +396,7 @@ async def test_api_create_array_with_rle_simple() -> None:
396396
arr = await zarr.api.asynchronous.create_array(
397397
store=store,
398398
shape=(60, 60),
399-
chunks=[[[10, 6]], [[10, 6]]],
399+
chunks=[[[10, 6]], [[10, 6]]], # type: ignore[list-item]
400400
dtype="i4",
401401
zarr_format=3,
402402
)
@@ -423,7 +423,7 @@ async def test_api_create_array_with_mixed_rle_and_explicit() -> None:
423423
arr = await zarr.api.asynchronous.create_array(
424424
store=store,
425425
shape=(6, 6),
426-
chunks=[[[2, 3]], [1, [2, 1], 3]],
426+
chunks=[[[2, 3]], [1, [2, 1], 3]], # type: ignore[list-item]
427427
dtype="f8",
428428
zarr_format=3,
429429
)
@@ -435,7 +435,7 @@ async def test_api_create_array_with_mixed_rle_and_explicit() -> None:
435435
data = np.random.random((6, 6))
436436
await arr.setitem(slice(None), data)
437437
result = await arr.getitem(slice(None))
438-
np.testing.assert_array_almost_equal(result, data)
438+
np.testing.assert_array_almost_equal(result, data) # type: ignore[arg-type]
439439

440440

441441
async def test_api_rle_chunk_grid_roundtrip_persistence() -> None:
@@ -447,7 +447,7 @@ async def test_api_rle_chunk_grid_roundtrip_persistence() -> None:
447447
store=store,
448448
name="rle_array",
449449
shape=(100, 50),
450-
chunks=[[[10, 10]], [[10, 5]]],
450+
chunks=[[[10, 10]], [[10, 5]]], # type: ignore[list-item]
451451
dtype="u2",
452452
zarr_format=3,
453453
)
@@ -479,10 +479,10 @@ async def test_api_rle_spec_example() -> None:
479479
store=store,
480480
shape=(6, 6, 6, 4, 6),
481481
chunks=[
482-
[[2, 3]],
483-
[[1, 6]],
484-
[1, [2, 1], 3],
485-
[[1, 3], 1],
482+
[[2, 3]], # type: ignore[list-item]
483+
[[1, 6]], # type: ignore[list-item]
484+
[1, [2, 1], 3], # type: ignore[list-item]
485+
[[1, 3], 1], # type: ignore[list-item]
486486
[6],
487487
],
488488
dtype="i1",
@@ -512,7 +512,7 @@ def test_api_synchronous_api_with_rle_chunks() -> None:
512512
arr = zarr.create_array(
513513
store=store,
514514
shape=(30, 40),
515-
chunks=[[[10, 3]], [[10, 4]]],
515+
chunks=[[[10, 3]], [[10, 4]]], # type: ignore[list-item]
516516
dtype="f4",
517517
zarr_format=3,
518518
)
@@ -523,7 +523,7 @@ def test_api_synchronous_api_with_rle_chunks() -> None:
523523
# Test write/read
524524
data = np.random.random((30, 40)).astype("f4")
525525
arr[:] = data
526-
np.testing.assert_array_almost_equal(arr[:], data)
526+
np.testing.assert_array_almost_equal(arr[:], data) # type: ignore[arg-type]
527527

528528

529529
async def test_api_rle_with_zero_count() -> None:
@@ -533,7 +533,7 @@ async def test_api_rle_with_zero_count() -> None:
533533
arr = await zarr.api.asynchronous.create_array(
534534
store=store,
535535
shape=(10, 10),
536-
chunks=[[[5, 0], 5, 5], [[5, 2]]],
536+
chunks=[[[5, 0], 5, 5], [[5, 2]]], # type: ignore[list-item]
537537
dtype="u1",
538538
zarr_format=3,
539539
)
@@ -556,7 +556,7 @@ def test_api_group_create_array_with_rle() -> None:
556556
arr = root.create_array(
557557
"rle_test",
558558
shape=(50, 50),
559-
chunks=[[[10, 5]], [[10, 5]]],
559+
chunks=[[[10, 5]], [[10, 5]]], # type: ignore[list-item]
560560
dtype="i8",
561561
)
562562

@@ -568,7 +568,7 @@ def test_api_group_create_array_with_rle() -> None:
568568

569569
# Verify the array is accessible from the group
570570
arr2 = root["rle_test"]
571-
assert isinstance(arr2.metadata.chunk_grid, RectilinearChunkGrid)
571+
assert isinstance(arr2.metadata.chunk_grid, RectilinearChunkGrid) # type: ignore[union-attr]
572572

573573

574574
async def test_api_rle_with_large_repeat_count() -> None:
@@ -578,7 +578,7 @@ async def test_api_rle_with_large_repeat_count() -> None:
578578
arr = await zarr.api.asynchronous.create_array(
579579
store=store,
580580
shape=(1000, 1000),
581-
chunks=[[[10, 100]], [[10, 100]]],
581+
chunks=[[[10, 100]], [[10, 100]]], # type: ignore[list-item]
582582
dtype="i2",
583583
zarr_format=3,
584584
)
@@ -603,7 +603,7 @@ async def test_api_rle_mixed_with_irregular_chunks() -> None:
603603
arr = await zarr.api.asynchronous.create_array(
604604
store=store,
605605
shape=(100, 100),
606-
chunks=[[[10, 5], 50], [25, 30, 20, 25]],
606+
chunks=[[[10, 5], 50], [25, 30, 20, 25]], # type: ignore[list-item]
607607
dtype="u4",
608608
zarr_format=3,
609609
)
@@ -630,7 +630,7 @@ async def test_api_v2_rejects_rle_chunks(zarr_format: Literal[2, 3]) -> None:
630630
await zarr.api.asynchronous.create_array(
631631
store=store,
632632
shape=(60, 60),
633-
chunks=[[[10, 6]], [[10, 6]]],
633+
chunks=[[[10, 6]], [[10, 6]]], # type: ignore[list-item]
634634
dtype="i4",
635635
zarr_format=zarr_format,
636636
)
@@ -648,6 +648,6 @@ async def test_api_from_array_rejects_rle_chunks() -> None:
648648
await zarr.api.asynchronous.from_array(
649649
store=store,
650650
data=data,
651-
chunks=[[[10, 3]], [[10, 3]]],
651+
chunks=[[[10, 3]], [[10, 3]]], # type: ignore[arg-type]
652652
zarr_format=3,
653653
)

0 commit comments

Comments
 (0)