8000 Merge branch 'main' into codecs-in-property-tests · zarr-developers/zarr-python@8ebb46b · GitHub
[go: up one dir, main page]

Skip to content

Commit 8ebb46b

Browse files
authored
Merge branch 'main' into codecs-in-property-tests
2 parents 29460a7 + 870265a commit 8ebb46b

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

changes/2817.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix fancy indexing (e.g. arr[5, [0, 1]]) with the sharding codec

src/zarr/codecs/sharding.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,11 @@ async def _decode_partial_single(
531531
],
532532
out,
533533
)
534-
return out
534+
535+
if hasattr(indexer, "sel_shape"):
536+
return out.reshape(indexer.sel_shape)
537+
else:
538+
return out
535539

536540
async def _encode_single(
537541
self,

tests/test_array.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1429,3 +1429,18 @@ def test_multiprocessing(store: Store, method: Literal["fork", "spawn", "forkser
14291429

14301430
results = pool.starmap(_index_array, [(arr, slice(len(data)))])
14311431
assert all(np.array_equal(r, data) for r in results)
1432+
1433+
1434+
async def test_sharding_coordinate_selection() -> None:
1435+
store = MemoryStore()
1436+
g = zarr.open_group(store, mode="w")
1437+
arr = g.create_array(
1438+
name="a",
1439+
shape=(2, 3, 4),
1440+
chunks=(1, 2, 2),
1441+
overwrite=True,
1442+
dtype=np.float32,
1443+
shards=(2, 4, 4),
1444+
)
1445+
arr[:] = np.arange(2 * 3 * 4).reshape((2, 3, 4))
1446+
assert (arr[1, [0, 1]] == np.array([[12, 13, 14, 15], [16, 17, 18, 19]])).all() # type: ignore[index]

0 commit comments

Comments
 (0)
0