Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions changes/3378.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Ensure passing `config` is handled properly when `open`ing an existing
array.

4 changes: 3 additions & 1 deletion src/zarr/api/asynchronous.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,9 @@ async def open(
zarr_format = _metadata_dict["zarr_format"]
is_v3_array = zarr_format == 3 and _metadata_dict.get("node_type") == "array"
if is_v3_array or zarr_format == 2:
return AsyncArray(store_path=store_path, metadata=_metadata_dict)
return AsyncArray(
store_path=store_path, metadata=_metadata_dict, config=kwargs.get("config")
)
except (AssertionError, FileNotFoundError, NodeTypeValidationError):
pass
return await open_group(store=store_path, zarr_format=zarr_format, mode=mode, **kwargs)
Expand Down
24 changes: 24 additions & 0 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,30 @@ def test_write_empty_chunks_warns(write_empty_chunks: bool, zarr_format: ZarrFor
)


@pytest.mark.parametrize("zarr_format", [2, 3])
def test_open_array_respects_write_empty_chunks_config(zarr_format: ZarrFormat) -> None:
"""Test that zarr.open() respects write_empty_chunks config."""
store = MemoryStore()

_ = zarr.create(
store=store,
path="test_array",
shape=(10,),
chunks=(5,),
dtype="f8",
fill_value=0.0,
zarr_format=zarr_format,
)

arr2 = zarr.open(store=store, path="test_array", config={"write_empty_chunks": True})
assert isinstance(arr2, zarr.Array)

assert arr2._async_array._config.write_empty_chunks is True

arr2[0:5] = np.zeros(5)
assert arr2.nchunks_initialized == 1


@pytest.mark.parametrize("path", ["foo", "/", "/foo", "///foo/bar"])
@pytest.mark.parametrize("node_type", ["array", "group"])
def test_open_normalized_path(
Expand Down
Loading