Skip to content

Commit 1a4aa5b

Browse files
authored
Fix: respect write_empty_chunks when opening an existing array (#3378)
* Fix: respect write_empty_chunks when opening an existing array * doc: add release notes
1 parent 2271067 commit 1a4aa5b

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

changes/3378.bugfix.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Ensure passing `config` is handled properly when `open`ing an existing
2+
array.
3+

src/zarr/api/asynchronous.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,9 @@ async def open(
358358
zarr_format = _metadata_dict["zarr_format"]
359359
is_v3_array = zarr_format == 3 and _metadata_dict.get("node_type") == "array"
360360
if is_v3_array or zarr_format == 2:
361-
return AsyncArray(store_path=store_path, metadata=_metadata_dict)
361+
return AsyncArray(
362+
store_path=store_path, metadata=_metadata_dict, config=kwargs.get("config")
363+
)
362364
except (AssertionError, FileNotFoundError, NodeTypeValidationError):
363365
pass
364366
return await open_group(store=store_path, zarr_format=zarr_format, mode=mode, **kwargs)

tests/test_api.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,30 @@ def test_write_empty_chunks_warns(write_empty_chunks: bool, zarr_format: ZarrFor
123123
)
124124

125125

126+
@pytest.mark.parametrize("zarr_format", [2, 3])
127+
def test_open_array_respects_write_empty_chunks_config(zarr_format: ZarrFormat) -> None:
128+
"""Test that zarr.open() respects write_empty_chunks config."""
129+
store = MemoryStore()
130+
131+
_ = zarr.create(
132+
store=store,
133+
path="test_array",
134+
shape=(10,),
135+
chunks=(5,),
136+
dtype="f8",
137+
fill_value=0.0,
138+
zarr_format=zarr_format,
139+
)
140+
141+
arr2 = zarr.open(store=store, path="test_array", config={"write_empty_chunks": True})
142+
assert isinstance(arr2, zarr.Array)
143+
144+
assert arr2._async_array._config.write_empty_chunks is True
145+
146+
arr2[0:5] = np.zeros(5)
147+
assert arr2.nchunks_initialized == 1
148+
149+
126150
@pytest.mark.parametrize("path", ["foo", "/", "/foo", "///foo/bar"])
127151
@pytest.mark.parametrize("node_type", ["array", "group"])
128152
def test_open_normalized_path(

0 commit comments

Comments
 (0)