From 7b852d7058c0641cf829d1e88e737026f29a5ee7 Mon Sep 17 00:00:00 2001 From: Ian Hunt-Isaak Date: Fri, 15 Aug 2025 12:13:35 -0400 Subject: [PATCH 1/2] Fix: respect write_empty_chunks when opening an existing array --- src/zarr/api/asynchronous.py | 4 +++- tests/test_api.py | 24 ++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/zarr/api/asynchronous.py b/src/zarr/api/asynchronous.py index a044ba8594..6caff8588b 100644 --- a/src/zarr/api/asynchronous.py +++ b/src/zarr/api/asynchronous.py @@ -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) diff --git a/tests/test_api.py b/tests/test_api.py index 69fc9b5b16..5447a0aa39 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -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( From df48627a29a1cca491da05e6dc5463533664f63f Mon Sep 17 00:00:00 2001 From: Ian Hunt-Isaak Date: Fri, 15 Aug 2025 12:17:49 -0400 Subject: [PATCH 2/2] doc: add release notes --- changes/3378.bugfix.rst | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 changes/3378.bugfix.rst diff --git a/changes/3378.bugfix.rst b/changes/3378.bugfix.rst new file mode 100644 index 0000000000..1107f76488 --- /dev/null +++ b/changes/3378.bugfix.rst @@ -0,0 +1,3 @@ +Ensure passing `config` is handled properly when `open`ing an existing +array. +