Skip to content

Fix save/load for scalar arrays#4103

Merged
d-v-b merged 1 commit into
zarr-developers:mainfrom
gaoflow:fix-scalar-save-array-ellipsis
Jun 26, 2026
Merged

Fix save/load for scalar arrays#4103
d-v-b merged 1 commit into
zarr-developers:mainfrom
gaoflow:fix-scalar-save-array-ellipsis

Conversation

@gaoflow

@gaoflow gaoflow commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Fixes #3469.

save_array() and load() used slice(None) as the full-array selection. That works for arrays with at least one dimension, but for 0-dimensional arrays it is interpreted as one index and raises IndexError: too many indices for array; expected 0, got 1.

This changes both paths to use Ellipsis, which still means full-array selection for N-dimensional arrays and normalizes to an empty selection for scalar arrays. The regression test covers Group.__setitem__ with both an integer scalar array and a bytes scalar array, then verifies direct indexing and zarr.load().

TODO:

  • Add unit tests and/or doctests in docstrings
  • Add docstrings and API docs for any new/modified user-facing classes and functions
  • New/modified features documented in docs/user-guide/*.md
  • Changes documented as a new file in changes/
  • GitHub Actions have all passed
  • Test coverage is 100% (Codecov passes)

Local verification:

  • uv run --frozen pytest tests/test_api.py::test_group_setitem_loads_scalar_arrays -q
  • uv run --frozen pytest tests/test_api.py::test_save tests/test_api.py::test_load_array tests/test_api.py::test_load_local tests/test_api.py::test_load_zip -q
  • uv run --frozen ruff check src/zarr/api/asynchronous.py tests/test_api.py
  • uv run --frozen ruff format --check src/zarr/api/asynchronous.py tests/test_api.py
  • uv run --frozen python -m compileall -q src/zarr/api/asynchronous.py tests/test_api.py
  • git diff --check

@codecov

codecov Bot commented Jun 26, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.50%. Comparing base (036ede7) to head (5d4f445).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4103   +/-   ##
=======================================
  Coverage   93.50%   93.50%           
=======================================
  Files          90       90           
  Lines       11981    11981           
=======================================
  Hits        11203    11203           
  Misses        778      778           
Files with missing lines Coverage Δ
src/zarr/api/asynchronous.py 94.05% <100.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@d-v-b d-v-b left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks!

@d-v-b d-v-b merged commit 8ebd1cc into zarr-developers:main Jun 26, 2026
30 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bytes array + ellipsis slicing -> IndexError: too many indices for array; expected 0, got 1

2 participants