Skip to content

Commit bb4da5e

Browse files
committed
skip morton indices out of bound
1 parent 58d79f8 commit bb4da5e

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

src/zarr/core/indexing.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1343,9 +1343,15 @@ def decode_morton(z: int, chunk_shape: ChunkCoords) -> ChunkCoords:
13431343

13441344

13451345
def morton_order_iter(chunk_shape: ChunkCoords) -> Iterator[ChunkCoords]:
1346-
for i in range(product(chunk_shape)):
1347-
yield decode_morton(i, chunk_shape)
1348-
1346+
i = 0
1347+
order = []
1348+
while len(order)<product(chunk_shape):
1349+
m = decode_morton(i, chunk_shape)
1350+
if m not in order and all(x < y for x,y in zip(m, chunk_shape, strict=False)):
1351+
order.append(m)
1352+
i+=1
1353+
for j in range(product(chunk_shape)):
1354+
yield order[j]
13491355

13501356
def c_order_iter(chunks_per_shard: ChunkCoords) -> Iterator[ChunkCoords]:
13511357
return itertools.product(*(range(x) for x in chunks_per_shard))

tests/v3/test_codecs/test_codecs.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,8 @@ def test_morton() -> None:
211211
[2, 2, 2],
212212
[5, 2],
213213
[2, 5],
214-
[2, 2, 2, 2],
215-
[1, 2, 0],
214+
[2, 9, 2],
215+
[3, 2, 12],
216216
[2, 5, 1],
217217
[4, 3, 6, 2, 7],
218218
[3, 2, 1, 6, 4, 5, 2],

0 commit comments

Comments
 (0)