Skip to content

Commit 578469f

Browse files
committed
Merge branch 'main' into creation-from-other-zarr
# Conflicts: # tests/test_array.py # tests/test_indexing.py
2 parents f15f5ac + 15d9260 commit 578469f

File tree

4 files changed

+23
-4
lines changed

4 files changed

+23
-4
lines changed

changes/2782.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Optimize full chunk writes

src/zarr/core/indexing.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1373,10 +1373,13 @@ def is_total_slice(item: Selection, shape: ChunkCoords) -> bool:
13731373
item = (item,)
13741374
if isinstance(item, tuple):
13751375
return all(
1376-
isinstance(dim_sel, slice)
1377-
and (
1378-
(dim_sel == slice(None))
1379-
or ((dim_sel.stop - dim_sel.start == dim_len) and (dim_sel.step in [1, None]))
1376+
(isinstance(dim_sel, int) and dim_len == 1)
1377+
or (
1378+
isinstance(dim_sel, slice)
1379+
and (
1380+
(dim_sel == slice(None))
1381+
or ((dim_sel.stop - dim_sel.start == dim_len) and (dim_sel.step in [1, None]))
1382+
)
13801383
)
13811384
for dim_sel, dim_len in zip(item, shape, strict=False)
13821385
)

tests/test_array.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import re
66
from itertools import accumulate
77
from typing import TYPE_CHECKING, Any, Literal
8+
from unittest import mock
89

910
import numcodecs
1011
import numpy as np
@@ -1438,3 +1439,11 @@ async def test_from_array_arraylike(
14381439
np.testing.assert_array_equal(result[...], np.array(src))
14391440
else:
14401441
np.testing.assert_array_equal(result[...], np.full_like(src, fill_value))
1442+
1443+
1444+
async def test_orthogonal_set_total_slice() -> None:
1445+
"""Ensure that a whole chunk overwrite does not read chunks"""
1446+
store = MemoryStore()
1447+
array = zarr.create_array(store, shape=(20, 20), chunks=(1, 2), dtype=int, fill_value=-1)
1448+
with mock.patch("zarr.storage.MemoryStore.get", side_effect=ValueError):
1449+
array[0, slice(4, 10)] = np.arange(6)

tests/test_indexing.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
OrthogonalSelection,
2020
Selection,
2121
_iter_grid,
22+
is_total_slice,
2223
make_slice_selection,
2324
normalize_integer_selection,
2425
oindex,
@@ -1963,3 +1964,8 @@ def test_iter_chunk_regions():
19631964
assert_array_equal(a[region], np.ones_like(a[region]))
19641965
a[region] = 0
19651966
assert_array_equal(a[region], np.zeros_like(a[region]))
1967+
1968+
1969+
def test_is_total_slice():
1970+
assert is_total_slice((0, slice(4, 6)), (1, 2))
1971+
assert is_total_slice((slice(0, 1, None), slice(4, 6)), (1, 2))

0 commit comments

Comments
 (0)