Skip to content

Commit a9531ca

Browse files
committed
Return scalar when accessing zero dimensional array
1 parent 45146ca commit a9531ca

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed

src/zarr/core/array.py

+2
Original file line numberDiff line numberDiff line change
@@ -1245,6 +1245,8 @@ async def _get_selection(
12451245
out_buffer,
12461246
drop_axes=indexer.drop_axes,
12471247
)
1248+
if indexer.shape == ():
1249+
return out_buffer.as_numpy_array().item()
12481250
return out_buffer.as_ndarray_like()
12491251

12501252
async def getitem(

tests/test_array.py

+2
Original file line numberDiff line numberDiff line change
@@ -1262,3 +1262,5 @@ async def test_scalar_array() -> None:
12621262
assert arr[...] == 1.5
12631263
assert arr[()] == 1.5
12641264
assert arr.shape == ()
1265+
assert isinstance(arr[()], float)
1266+
assert arr.ndim == 0

0 commit comments

Comments
 (0)