Skip to content

fix(group): apply config when require_array returns an existing array - #4413

Merged
d-v-b merged 6 commits into
zarr-developers:mainfrom
d-v-b:fix/require-array-config
Sep 30, 2026
Merged

d-v-b merged 6 commits into
zarr-developers:mainfrom
d-v-b:fix/require-array-config

Conversation

@d-v-b

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

Copy link
Copy Markdown
Contributor

Part of the kwargs audit, here's a parameter (config) not being propagated correctly through the chain of function calls. this PR fixes that.

🤖 AI text below 🤖

Group.require_array (sync and async) forwarded **kwargs, including config, only to create_array in the branch that creates a missing array. When the array already existed, config was silently dropped:

g = zarr.group(zarr.storage.MemoryStore())
g.create_array("a", shape=(4,), dtype="uint8")
r = g.require_array("a", shape=(4,), dtype="uint8", config={"write_empty_chunks": True})
r.config.write_empty_chunks  # False before this PR, True after

This is the same bug as #4408 (open_array), found in the same **kwargs audit.

Changes

  • config is a named parameter of Group.require_array and AsyncGroup.require_array, passed explicitly to both branches. Reading it from **kwargs is what let the existing-array branch drop it.
  • New array: config goes to create_array.
  • Existing array: after the shape and dtype checks, the array is returned through .with_config(config). The existing array comes from getitem, which serves member lookup in general (including consolidated metadata) and takes no runtime config, so adding one there would be out of place. with_config reuses the metadata and only rebuilds the codec pipeline.
  • One parser for both branches: the existing-array branch runs config through parse_array_config before with_config, so an unknown key raises the same TypeError("Unknown array config keys: [...]") whether the array exists or is created, and missing keys come from the global configuration in both cases.

Behaviour change: an invalid config given for an existing array used to be ignored, and now raises (TypeError for an unknown key, ValueError for an invalid value).

Tests

  • test_require_array_config: zarr format 2/3 × sync/async × existing/new array × config as None, a partial dict, a multi-key dict, or an ArrayConfig.
  • test_require_array_unknown_config_key and test_require_array_invalid_config_value: one test per error case, each run against an existing and a newly created array.

14 of the new cases fail on main. The full test suite passes locally, and so does mypy.

Not covered

The other kwargs are still ignored for an existing array without a warning: stored-metadata arguments such as fill_value, chunks, attributes and overwrite, and unknown keys (which raise only on the create branch). How those should behave is an open question, and this PR doesn't answer it.

🤖 Generated with Claude Code

require_array forwarded **kwargs, including config, only to create_array
in the branch that creates a missing array. Requiring an existing array
dropped config and returned it with the global defaults. Apply it with
with_config(), as open_array does since zarr-developers#4408.

Assisted-by: ClaudeCode:claude-opus-5-5
Assisted-by: ClaudeCode:claude-opus-5-5
@codecov

codecov Bot commented Sep 25, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.45%. Comparing base (9e631c6) to head (9a025b2).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4413   +/-   ##
=======================================
  Coverage   94.44%   94.45%           
=======================================
  Files          93       93           
  Lines       13221    13224    +3     
=======================================
+ Hits        12487    12491    +4     
+ Misses        734      733    -1     
Files with missing lines Coverage Δ
src/zarr/core/group.py 95.55% <100.00%> (+0.12%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

config was read from **kwargs, which is how the existing-array branch
came to drop it. It is now a named parameter of Group.require_array and
AsyncGroup.require_array, passed explicitly to create_array for a new
array and applied with with_config() to an existing one. The existing
array comes from getitem, which serves member lookup in general
(including consolidated metadata) and takes no runtime config.

Assisted-by: ClaudeCode:claude-opus-5-5
@d-v-b d-v-b added this to the 3.4.1 milestone Sep 29, 2026
@d-v-b
d-v-b marked this pull request as ready for review September 30, 2026 08:02
The existing-array branch handed config to with_config, which merged
it over the array's current config and rejected an unknown key with the
dataclass's "unexpected keyword argument" message. The create branch
went through parse_array_config, which fills missing keys from the
global configuration and says "Unknown array config keys". The same bad
input now raises the same error whichever branch runs, and the docstring's
"taken from the global configuration" holds by construction.

The error tests run on both branches, and the combinations test passes
config=None explicitly instead of omitting the keyword.

Assisted-by: ClaudeCode:claude-fable-5-1
@d-v-b
d-v-b merged commit c79f736 into zarr-developers:main Sep 30, 2026
36 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