Skip to content

Fix: respect write_empty_chunks when opening an existing array #3378

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 18, 2025

Conversation

ianhi
Copy link
Contributor

@ianhi ianhi commented Aug 15, 2025

When you opened an existing array the write_empty_chunks config was being ignored. As indirectly reported in pydata/xarray#10633 this fixes the one branch of this function where the config was not being handled

minimal zarr reproducer

#!/usr/bin/env -S uv run
# /// script
# requires-python = ">=3.10"
# dependencies = [
#     "zarr@git+https://github.com/zarr-developers/zarr-python.git@main",
#     "numpy",
# ]
# ///

import os

import numpy as np
import zarr

# Create array
store = zarr.open_group("test.zarr", mode="w")
arr = store.create(
    "data",
    shape=(20,),
    chunks=(10,),
    dtype="f8",
    fill_value=0.0,
    config={"write_empty_chunks": True},
)

# Reopen (like xarray does with regions)
store = zarr.open_group("test.zarr", mode="r+")
arr = zarr.open(store=store.store, path="data", config={"write_empty_chunks": True})

# Write zeros - should create chunk but doesn't
arr[0:10] = np.zeros(10)

# Check what was written
chunk_dir = "test.zarr/data/c"
chunks = (
    [f for f in os.listdir(chunk_dir) if f.isdigit()]
    if os.path.exists(chunk_dir)
    else []
)
print(f"Chunks written: {sorted(chunks)}")
print("Expected: ['0'] (chunk with zeros should be written)")
  • Add unit tests and/or doctests in docstrings
  • [NA] Add docstrings and API docs for any new/modified user-facing classes and functions
  • [NA] New/modified features documented in docs/user-guide/*.rst
  • Changes documented as a new file in changes/
  • GitHub Actions have all passed
  • Test coverage is 100% (Codecov passes)

@github-actions github-actions bot added the needs release notes Automatically applied to PRs which haven't added release notes label Aug 15, 2025
@github-actions github-actions bot removed the needs release notes Automatically applied to PRs which haven't added release notes label Aug 15, 2025
Copy link

codecov bot commented Aug 15, 2025

Codecov Report

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

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3378   +/-   ##
=======================================
  Coverage   94.55%   94.55%           
=======================================
  Files          79       79           
  Lines        9448     9448           
=======================================
  Hits         8934     8934           
  Misses        514      514           
Files with missing lines Coverage Δ
src/zarr/api/asynchronous.py 87.62% <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 merged commit 1a4aa5b into zarr-developers:main Aug 18, 2025
31 checks passed
@ianhi ianhi deleted the fix/write-empty-chunks-config branch August 18, 2025 15:56
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.

2 participants