Skip to content

feat(api): declare mode and data on create - #4455

Merged
d-v-b merged 3 commits into
zarr-developers:mainfrom
d-v-b:fix/create-explicit-mode-data
Sep 30, 2026
Merged

d-v-b merged 3 commits into
zarr-developers:mainfrom
d-v-b:fix/create-explicit-mode-data

Conversation

@d-v-b

@d-v-b d-v-b commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

This PR makes zarr.create and zarr.api.asynchronous.create have accurate signatures and docstrings. part of **kwargs removal.

🤖 AI text below 🤖

zarr.create and zarr.api.asynchronous.create now list mode and data in their signatures and docstrings. Both were accepted before without being declared. An unknown keyword now raises a TypeError from create before anything in the store is touched. Previously, with mode="w", the existing data was deleted before the error was raised. mode is documented as a legacy spelling; overwrite is preferred.

This is the first step of replacing **kwargs in the array-creation helpers (empty, zeros, ones, full, the *_like functions and open_array) with explicit parameters. Before this change, create passed **kwargs on to AsyncArray._create, and the only extra names that function accepted were mode (which create popped out of kwargs) and data. The docs still rely on mode (zarr.zeros(..., mode='w') in docs/user-guide/experimental.md), so it stays, documented as legacy. data is documented with a pointer to create_array(data=...), whose data sets the shape and data type, unlike create's.

  • The docstring states each mode's outcome, including how it combines with overwrite: 'w' replaces even with overwrite=False, and 'w-' fails even with overwrite=True.
  • Tests: one test covers the successful combinations of mode, overwrite, an existing array and data, for both the sync and async create. It compares the stored keys with a fresh store, so it fails if old chunks or unrelated keys survive a replacement. There is one test per error case: an existing array without overwrite (default mode, 'a', 'r+'), 'w-' over existing data, 'r', an invalid mode, and an unknown keyword (sync and async, store left untouched).
  • Behavior is unchanged, except for where the TypeError for an unknown keyword comes from and that it is raised before mode="w" deletes anything.
  • Type checkers now reject a mode annotated as plain str, as open and open_array already do.
Notes

🤖 Generated with Claude Code

`create` accepted `mode` and `data` only through `**kwargs`: `mode` was
popped for opening the store and `data` reached `AsyncArray._create`.
Both are now named, documented parameters of the sync and async
`create`, and `**kwargs` is gone, so an unknown keyword raises a
TypeError from `create` itself.

Assisted-by: ClaudeCode:claude-opus-5-5
Assisted-by: ClaudeCode:claude-opus-5-5
@d-v-b
d-v-b marked this pull request as ready for review September 30, 2026 16:22
@codecov

codecov Bot commented Sep 30, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.46%. Comparing base (9677081) to head (4dc06f0).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4455   +/-   ##
=======================================
  Coverage   94.46%   94.46%           
=======================================
  Files          93       93           
  Lines       13234    13233    -1     
=======================================
  Hits        12501    12501           
+ Misses        733      732    -1     
Files with missing lines Coverage Δ
src/zarr/api/asynchronous.py 96.30% <ø> (-0.02%) ⬇️
src/zarr/api/synchronous.py 92.95% <ø> (ø)

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

…vior

Adversarial review of zarr-developers#4455 found the new docstrings overpromised:
`data` is not `array[...] = data` for a zarr Array, `'r'` does not
always open the store read-only, and the `mode`/`overwrite`
interaction was undocumented. `mode` is now documented as the legacy
spelling with `overwrite` preferred, each mode's outcome is stated,
and `data` points to `create_array(data=...)`.

The tests now cover the async `create`, the default mode, the
`mode`/`overwrite` combinations, that `'w'` removes old chunks and
stray keys, invalid modes, and that an unknown keyword leaves the
store untouched. The fragment moves to misc.

Assisted-by: ClaudeCode:claude-opus-5-5
@d-v-b
d-v-b merged commit 083adfc into zarr-developers:main Sep 30, 2026
39 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.

1 participant