Skip to content

refactor(api): list create's parameters on empty, zeros, ones and full - #4457

Draft
d-v-b wants to merge 7 commits into
zarr-developers:mainfrom
d-v-b:refactor/array-helpers-explicit-params
Draft

d-v-b wants to merge 7 commits into
zarr-developers:mainfrom
d-v-b:refactor/array-helpers-explicit-params

Conversation

@d-v-b

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

Copy link
Copy Markdown
Contributor

🤖 AI text below 🤖

zarr.empty, zeros, ones and full, their zarr.api.asynchronous versions, and Group/AsyncGroup empty, zeros, ones and full now list their parameters instead of taking **kwargs. The parameters are those of zarr.create. The group methods do not take store, path or storage_options, which the group supplies. An unknown keyword now raises a TypeError naming the function called. Passing data to these functions is deprecated; it fills the new array with data instead of the value the function is named for. To create an array from existing data, use zarr.create_array(data=...). Passing mode to the group methods is deprecated, because it never had an effect there.

This is the second step of replacing **kwargs in the array-creation helpers with explicit parameters. The *_like functions and open_array/open_like follow in separate PRs.

  • The signatures are identical to create's, parameter for parameter, including the seven parameters that create accepts but does not implement (synchronizer, chunk_store, cache_metadata, cache_attrs, object_codec, read_only, meta_array). They are still forwarded and still warn in create. Removing them is left to the deprecation sweep, so it applies to create and the helpers together.
  • zeros/ones do not take fill_value, which is already a TypeError today. full keeps fill_value as its second positional parameter.
  • The group methods take zarr_format as a named parameter and check it against the group, replacing the kwargs.pop("zarr_format", None) calls added in fix(group): create group helper arrays in the group's zarr format #4412. storage_options was already rejected for arrays in a group (make_store_path raises for a StorePath); it is now a TypeError at the call.
  • Docstrings document shape, fill_value, name, zarr_format and the deprecated parameters, and refer to create for the rest.
  • Tests:
    • The signatures are compared with create's, so the helpers cannot drift from it.
    • Every argument is checked to reach create unchanged at each layer (async, sync, AsyncGroup, Group), using a recording stand-in.
    • There is one test for each of: the data deprecation, the group mode deprecation, and unknown keywords (including store/path on the group methods).
    • The agent checked that the tests fail when a forwarded argument is dropped, a warning is removed, or **kwargs is restored.
Notes

🤖 Generated with Claude Code

Group.empty/zeros/ones/full and their *_like versions forwarded **kwargs
to the top-level creation functions without the group's zarr_format, so
a zarr v2 group got zarr v3 arrays. The group lists only members of its
own format, so each array was written into the group without becoming a
member of it. Pass the group's format, and raise when the caller asks
for another.

Creating an array in one format like an array of the other then failed,
because _like_args copied format-specific codec settings (compressor and
filters, or codecs). _like_args now takes the target format and copies
those settings only when the formats match. Top-level *_like functions
inherit the source's format unless another is requested; open_like does
not, because open_array would then look for an existing array in only
that format.

Assisted-by: ClaudeCode:claude-opus-5-5
Assisted-by: ClaudeCode:claude-opus-5-5
`empty_like`, `zeros_like`, `ones_like`, `full_like` and `open_like` read the
target format with `kwargs.get("zarr_format")` and then merged `kwargs` over
the arguments derived from the source array. An explicit `zarr_format=None`
therefore made `_like_args` inherit the source's format and copy its codecs,
after which the merge put `None` back and `create` chose the default format:
`zarr.zeros_like(v2_array, zarr_format=None)` raised because v2 compressor
settings reached a v3 array. `zarr_format` is now a keyword-only parameter,
and `_like_args` records the resolved format in the arguments it returns.

Assisted-by: ClaudeCode:claude-opus-5-5
The top-level `empty`, `zeros`, `ones` and `full` (sync and async) and
the `AsyncGroup`/`Group` versions forwarded `**kwargs` to `create`.
They now declare `create`'s parameters, with the same defaults, and
forward each one explicitly. The group methods leave out `store`,
`path` and `storage_options`, which the group supplies, and take
`zarr_format` as a named parameter instead of popping it from kwargs.

`data` is deprecated on these functions: it fills the "zeros" array
with other values. `mode` is deprecated on the group methods, where
the group's store is already open and it never had an effect.

Tests pin the signatures against `create`, check that every argument
is forwarded unchanged at each layer, and cover the deprecations and
unknown keywords.

Assisted-by: ClaudeCode:claude-opus-5-5
Assisted-by: ClaudeCode:claude-opus-5-5
@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.49%. Comparing base (083adfc) to head (48389b0).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4457      +/-   ##
==========================================
+ Coverage   94.46%   94.49%   +0.02%     
==========================================
  Files          93       93              
  Lines       13233    13267      +34     
==========================================
+ Hits        12501    12536      +35     
+ Misses        732      731       -1     
Files with missing lines Coverage Δ
src/zarr/api/asynchronous.py 96.55% <100.00%> (+0.24%) ⬆️
src/zarr/api/synchronous.py 94.36% <100.00%> (+1.40%) ⬆️
src/zarr/core/group.py 95.67% <100.00%> (+0.06%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

This branch has not been deployed

No deployments
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