Skip to content

fix: let open_like create arrays by default#4146

Open
goutamadwant wants to merge 1 commit into
zarr-developers:mainfrom
goutamadwant:fix-open-like-mode
Open

fix: let open_like create arrays by default#4146
goutamadwant wants to merge 1 commit into
zarr-developers:mainfrom
goutamadwant:fix-open-like-mode

Conversation

@goutamadwant

Copy link
Copy Markdown

Summary

Closes #3352.

zarr.api.asynchronous.open_like is intended to create or open a persistent array using metadata copied from an existing array. When callers omitted mode, or passed mode=None, it delegated to open_array without a create-capable mode and raised ArrayNotFoundError for a missing target path.

This changes open_like so an omitted or None mode defaults to "a" before delegating to open_array. Explicit modes are still passed through unchanged.

The regression test covers both Zarr v2 and v3, with mode omitted and with mode=None.

For reviewers

The main behavior choice is defaulting only open_like to append/create mode. I left open_array unchanged so this stays focused on the helper whose purpose is to create a similar persistent array.

Verified with:

  • uv run pytest -q tests/test_api.py::test_open_like_creates_array_by_default tests/test_api.py::test_array_like_creation --tb=short
  • uv run pytest -q tests/test_api.py --tb=short
  • uvx prek run --files src/zarr/api/asynchronous.py tests/test_api.py changes/3352.bugfix.md

Author attestation

  • I am a human, these are my changes, and I have reviewed and understood every change and can explain why each is correct.

AI coding assistance is welcome, but a human must be the author and is responsible for the contents of the PR. The description and any review responses must be in your own words. Please read AI-assisted contributions before opening.

TODO

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

@codecov

codecov Bot commented Jul 15, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.84%. Comparing base (d916f75) to head (2af64ca).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4146   +/-   ##
=======================================
  Coverage   93.84%   93.84%           
=======================================
  Files          91       91           
  Lines       12570    12572    +2     
=======================================
+ Hits        11796    11798    +2     
  Misses        774      774           
Files with missing lines Coverage Δ
src/zarr/api/asynchronous.py 96.32% <100.00%> (+0.02%) ⬆️
🚀 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 commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

looks good, thanks for fixing this.

requested changes

  • can you add a test that probes the intersection between a read-only store and a mutable access mode (like "a")? We expect this to error.
  • can you add a note to the changelog that users with a read-only store will need to explicitly declare mode="r" when using these routines
  • can you add docstrings to the open_like routines that explain what the default mode is.

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.

zarr.api.asynchronous.open_like is broken

2 participants