Skip to content

Commit 0c81853

Browse files
committed
fix: respect config when appending to array from zarr.open_array
1 parent 43c9c7e commit 0c81853

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

src/zarr/api/asynchronous.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1251,13 +1251,24 @@ async def open_array(
12511251

12521252
zarr_format = _handle_zarr_version_or_format(zarr_version=zarr_version, zarr_format=zarr_format)
12531253

1254+
config: ArrayConfigParams = kwargs.get("config", {})
12541255
if "order" in kwargs:
12551256
_warn_order_kwarg()
12561257
if "write_empty_chunks" in kwargs:
1257-
_warn_write_empty_chunks_kwarg()
1258+
if len(config) != 0:
1259+
msg = (
1260+
"Both write_empty_chunks and config keyword arguments are set. "
1261+
"This is redundant. When both are set, write_empty_chunks will be ignored and "
1262+
"config will be used."
1263+
)
1264+
warnings.warn(UserWarning(msg), stacklevel=1)
1265+
else:
1266+
_warn_write_empty_chunks_kwarg()
1267+
# don't pop as this is only used for AsyncArray.open
1268+
config["write_empty_chunks"] = kwargs["write_empty_chunks"]
12581269

12591270
try:
1260-
return await AsyncArray.open(store_path, zarr_format=zarr_format)
1271+
return await AsyncArray.open(store_path, zarr_format=zarr_format, config=config)
12611272
except FileNotFoundError:
12621273
if not store_path.read_only and mode in _CREATE_MODES:
12631274
overwrite = _infer_overwrite(mode)

src/zarr/core/array.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -869,6 +869,7 @@ async def open(
869869
cls,
870870
store: StoreLike,
871871
zarr_format: ZarrFormat | None = 3,
872+
config: ArrayConfigLike | None = None,
872873
) -> AsyncArray[ArrayV3Metadata] | AsyncArray[ArrayV2Metadata]:
873874
"""
874875
Async method to open an existing Zarr array from a given store.
@@ -879,6 +880,8 @@ async def open(
879880
The store containing the Zarr array.
880881
zarr_format : ZarrFormat | None, optional
881882
The Zarr format version (default is 3).
883+
config : ArrayConfigLike, optional
884+
Runtime configuration for the array.
882885
883886
Returns
884887
-------
@@ -896,7 +899,7 @@ async def open(
896899
metadata_dict = await get_array_metadata(store_path, zarr_format=zarr_format)
897900
# TODO: remove this cast when we have better type hints
898901
_metadata_dict = cast(ArrayV3MetadataDict, metadata_dict)
899-
return cls(store_path=store_path, metadata=_metadata_dict)
902+
return cls(store_path=store_path, metadata=_metadata_dict, config=config)
900903

901904
@property
902905
def store(self) -> Store:

0 commit comments

Comments
 (0)