Skip to content

Commit 5af3bb8

Browse files
committed
Revert "Error on invalid store mode (zarr-developers#3068)"
This reverts commit 481550a.
1 parent 84a1dd6 commit 5af3bb8

File tree

5 files changed

+8
-20
lines changed

5 files changed

+8
-20
lines changed

changes/3068.bugfix.rst

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/zarr/storage/_common.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import importlib.util
44
import json
55
from pathlib import Path
6-
from typing import TYPE_CHECKING, Any, Literal, Self, TypeAlias
6+
from typing import TYPE_CHECKING, Any, Literal, TypeAlias
77

88
from zarr.abc.store import ByteRequest, Store
99
from zarr.core.buffer import Buffer, default_buffer_prototype
@@ -55,7 +55,9 @@ def read_only(self) -> bool:
5555
return self.store.read_only
5656

5757
@classmethod
58-
async def open(cls, store: Store, path: str, mode: AccessModeLiteral | None = None) -> Self:
58+
async def open(
59+
cls, store: Store, path: str, mode: AccessModeLiteral | None = None
60+
) -> StorePath:
5961
"""
6062
Open StorePath based on the provided mode.
6163
@@ -72,9 +74,6 @@ async def open(cls, store: Store, path: str, mode: AccessModeLiteral | None = No
7274
------
7375
FileExistsError
7476
If the mode is 'w-' and the store path already exists.
75-
ValueError
76-
If the mode is not "r" and the store is read-only, or
77-
if the mode is "r" and the store is not read-only.
7877
"""
7978

8079
await store._ensure_open()
@@ -86,8 +85,6 @@ async def open(cls, store: Store, path: str, mode: AccessModeLiteral | None = No
8685

8786
if store.read_only and mode != "r":
8887
raise ValueError(f"Store is read-only but mode is '{mode}'")
89-
if not store.read_only and mode == "r":
90-
raise ValueError(f"Store is not read-only but mode is '{mode}'")
9188

9289
match mode:
9390
case "w-":

tests/test_api.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ def test_v2_and_v3_exist_at_same_path(store: Store) -> None:
171171
zarr.create_array(store, shape=(10,), dtype="uint8", zarr_format=2)
172172
msg = f"Both zarr.json (Zarr format 3) and .zarray (Zarr format 2) metadata objects exist at {store}. Zarr v3 will be used."
173173
with pytest.warns(UserWarning, match=re.escape(msg)):
174-
zarr.open(store=store)
174+
zarr.open(store=store, mode="r")
175175

176176

177177
@pytest.mark.parametrize("store", ["memory"], indirect=True)
@@ -1318,7 +1318,7 @@ def test_no_overwrite_open(tmp_path: Path, open_func: Callable, mode: str) -> No
13181318
existing_fpath = add_empty_file(tmp_path)
13191319

13201320
assert existing_fpath.exists()
1321-
with contextlib.suppress(FileExistsError, FileNotFoundError, ValueError):
1321+
with contextlib.suppress(FileExistsError, FileNotFoundError):
13221322
open_func(store=store, mode=mode)
13231323
if mode == "w":
13241324
assert not existing_fpath.exists()

tests/test_array.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1479,7 +1479,7 @@ async def test_name(store: Store, zarr_format: ZarrFormat, path: str | None) ->
14791479
for parent_path in parents:
14801480
# this will raise if these groups were not created
14811481
_ = await zarr.api.asynchronous.open_group(
1482-
store=store, path=parent_path, zarr_format=zarr_format
1482+
store=store, path=parent_path, mode="r", zarr_format=zarr_format
14831483
)
14841484

14851485

@@ -1667,7 +1667,7 @@ def test_roundtrip_numcodecs() -> None:
16671667

16681668
BYTES_CODEC = {"name": "bytes", "configuration": {"endian": "little"}}
16691669
# Read in the array again and check compressor config
1670-
root = zarr.open_group(store)
1670+
root = zarr.open_group(store, mode="r")
16711671
metadata = root["test"].metadata.to_dict()
16721672
expected = (*filters, BYTES_CODEC, *compressors)
16731673
assert metadata["codecs"] == expected

tests/test_store/test_core.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import pytest
55
from _pytest.compat import LEGACY_PATH
66

7-
import zarr
87
from zarr import Group
98
from zarr.core.common import AccessModeLiteral, ZarrFormat
109
from zarr.storage import FsspecStore, LocalStore, MemoryStore, StoreLike, StorePath
@@ -261,10 +260,3 @@ def test_relativize_path_invalid() -> None:
261260
msg = f"The first component of {path} does not start with {prefix}."
262261
with pytest.raises(ValueError, match=msg):
263262
_relativize_path(path="a/b/c", prefix="b")
264-
265-
266-
def test_invalid_open_mode() -> None:
267-
store = MemoryStore()
268-
zarr.create((100,), store=store, zarr_format=2, path="a")
269-
with pytest.raises(ValueError, match="Store is not read-only but mode is 'r'"):
270-
zarr.open_array(store=store, path="a", zarr_format=2, mode="r")

0 commit comments

Comments
 (0)