Skip to content

Commit 3e43b1f

Browse files
committed
proper fix
1 parent 55ebb31 commit 3e43b1f

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

src/zarr/codecs/sharding.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -481,12 +481,8 @@ async def _decode_partial_single(
481481
)
482482

483483
# setup output array
484-
if hasattr(indexer, "sel_shape"):
485-
out_shape = indexer.sel_shape
486-
else:
487-
out_shape = indexer.shape
488484
out = shard_spec.prototype.nd_buffer.create(
489-
shape=out_shape, dtype=shard_spec.dtype, order=shard_spec.order, fill_value=0
485+
shape=indexer.shape, dtype=shard_spec.dtype, order=shard_spec.order, fill_value=0
490486
)
491487

492488
indexed_chunks = list(indexer)
@@ -533,7 +529,11 @@ async def _decode_partial_single(
533529
],
534530
out,
535531
)
536-
return out
532+
533+
if hasattr(indexer, "sel_shape"):
534+
return out.reshape(indexer.sel_shape)
535+
else:
536+
return out
537537

538538
async def _encode_single(
539539
self,

tests/test_array.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1427,11 +1427,11 @@ async def test_sharding_coordinate_selection() -> None:
14271427
g = zarr.open_group(store, mode="w")
14281428
arr = g.create_array(
14291429
name="a",
1430-
shape=(10, 20, 30),
1431-
chunks=(5, 1, 30),
1430+
shape=(2, 3, 4),
1431+
chunks=(1, 2, 2),
14321432
overwrite=True,
14331433
dtype=np.float32,
1434-
shards=(5, 20, 30),
1434+
shards=(2, 4, 4),
14351435
)
1436-
arr[:] = np.arange(10*20*30).reshape((10, 20, 30))
1437-
assert (arr[5, [0, 1]] == np.vstack([np.arange(3000, 3030), np.arange(3030, 3060)])).all()
1436+
arr[:] = np.arange(2 * 3 * 4).reshape((2, 3, 4))
1437+
assert (arr[1, [0, 1]] == np.array([[12, 13, 14, 15], [16, 17, 18, 19]])).all()

0 commit comments

Comments
 (0)