Skip to content

Commit

Permalink
Merge branch 'main' into RSE
Browse files Browse the repository at this point in the history
  • Loading branch information
jhamman authored May 17, 2024
2 parents 1652309 + bf89533 commit c337869
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 2 deletions.
4 changes: 4 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ updates:
directory: "/"
schedule:
interval: "daily"
groups:
requirements:
patterns:
- "*"
- package-ecosystem: "github-actions"
directory: "/"
schedule:
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ default_language_version:
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: 'v0.4.3'
rev: 'v0.4.4'
hooks:
- id: ruff
- repo: https://github.com/psf/black
Expand Down
10 changes: 10 additions & 0 deletions docs/release.rst
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,16 @@ Maintenance
Deprecations
~~~~~~~~~~~~

.. _release_2.18.1:

2.18.1
------

Maintenance
~~~~~~~~~~~
* Fix a regression when getting or setting a single value from arrays with size-1 chunks.
By :user:`Deepak Cherian <dcherian>` :issue:`1874`

.. _release_2.18.0:

2.18.0
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
2 changes: 2 additions & 0 deletions zarr/indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ def is_scalar(value, dtype):
return True
if isinstance(value, tuple) and dtype.names and len(value) == len(dtype.names):
return True
if dtype.kind == "O" and not isinstance(value, np.ndarray):
return True
return False


Expand Down
49 changes: 49 additions & 0 deletions zarr/tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -3157,3 +3157,52 @@ 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)

store["a"][slice(1)] = [-1]
assert store["a"][0] == np.array(-1)

store["a"][0] = -2
assert store["a"][0] == np.array(-2)

store["a"][slice(1)] = (-3,)
assert store["a"][0] == np.array(-3)


def test_object_array_indexing():
# regression test for #1874
from numcodecs import MsgPack

root = zarr.group()
arr = root.create_dataset(
name="my_dataset",
shape=0,
dtype=object,
object_codec=MsgPack(),
)
new_items = [
["A", 1],
["B", 2, "hello"],
]
arr_add = np.empty(len(new_items), dtype=object)
arr_add[:] = new_items
arr.append(arr_add)

# heterogeneous elements
elem = ["C", 3]
arr[0] = elem
assert arr[0] == elem

# homogeneous elements
elem = [1, 3]
arr[1] = elem
assert arr[1] == elem

0 comments on commit c337869

Please sign in to comment.