Skip to content

Commit

Permalink
Fix a regression with scalar indexing due to zarr-developers#1800
Browse files Browse the repository at this point in the history
  • Loading branch information
dcherian committed May 13, 2024
1 parent cb4230d commit 49e8c53
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
2 changes: 2 additions & 0 deletions docs/release.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ Docs

Maintenance
~~~~~~~~~~~
* Fix a regression when indexing out a single value from arrays with size-1 chunks.
By :user:`Deepak Cherian <dcherian>`

Deprecations
~~~~~~~~~~~~
Expand Down
4 changes: 3 additions & 1 deletion zarr/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -2030,7 +2030,9 @@ def _process_chunk(
and not self._filters
and self._dtype != object
):
dest = out[out_selection]
# For 0D arrays out_selection = () and out[out_selection] is a scalar
# Avoid that
dest = out[out_selection] if out_selection else out
# Assume that array-like objects that doesn't have a
# `writeable` flag is writable.
dest_is_writable = getattr(dest, "writeable", True)
Expand Down
10 changes: 10 additions & 0 deletions zarr/tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -3157,3 +3157,13 @@ def test_issue_1279(tmpdir):

written_data = ds_reopened[:]
assert_array_equal(data, written_data)


def test_scalar_indexing():
store = zarr.KVStore({})

store["a"] = zarr.create((3,), chunks=(1,), store=store)
store["a"][:] = [1, 2, 3]

assert store["a"][1] == np.array(2.0)
assert store["a"][(1,)] == np.array(2.0)

0 comments on commit 49e8c53

Please sign in to comment.