Skip to content

Commit 95ae4b6

Browse files
normanrzd-v-bjhamman
authored
Remove ArrayV2 (#1857)
* adds wrapper codecs for the v2 codec pipeline * encode_chunk_key * refactor ArrayV2 away * empty zattrs * Apply suggestions from code review Co-authored-by: Davis Bennett <davis.v.bennett@gmail.com> * unify ArrayMetadata * abstract ArrayMetadata * unified Array.create * use zarr.config for batch_size * __init__.py aktualisieren Co-authored-by: Joe Hamman <joe@earthmover.io> * ruff --------- Co-authored-by: Davis Bennett <davis.v.bennett@gmail.com> Co-authored-by: Joe Hamman <joe@earthmover.io>
1 parent 3a85a0a commit 95ae4b6

File tree

14 files changed

+672
-742
lines changed

14 files changed

+672
-742
lines changed

src/zarr/__init__.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
from __future__ import annotations
22

3-
from typing import Union
4-
53
import zarr.codecs # noqa: F401
64
from zarr.array import Array, AsyncArray
7-
from zarr.array_v2 import ArrayV2
85
from zarr.config import config # noqa: F401
96
from zarr.group import AsyncGroup, Group
107
from zarr.store import (
@@ -18,19 +15,15 @@
1815
assert not __version__.startswith("0.0.0")
1916

2017

21-
async def open_auto_async(
22-
store: StoreLike,
23-
) -> Union[AsyncArray, AsyncGroup]:
18+
async def open_auto_async(store: StoreLike) -> AsyncArray | AsyncGroup:
2419
store_path = make_store_path(store)
2520
try:
2621
return await AsyncArray.open(store_path)
2722
except KeyError:
2823
return await AsyncGroup.open(store_path)
2924

3025

31-
def open_auto(
32-
store: StoreLike,
33-
) -> Union[Array, ArrayV2, Group]:
26+
def open_auto(store: StoreLike) -> Array | Group:
3427
object = _sync(
3528
open_auto_async(store),
3629
)

src/zarr/abc/codec.py

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
from __future__ import annotations
22

33
from abc import abstractmethod
4-
from typing import TYPE_CHECKING, Generic, Iterable, Protocol, TypeVar, runtime_checkable
4+
from typing import TYPE_CHECKING, Generic, Iterable, TypeVar
55

66
import numpy as np
77
from zarr.abc.metadata import Metadata
8+
from zarr.abc.store import ByteGetter, ByteSetter
89
from zarr.common import BytesLike
910

1011

@@ -14,20 +15,6 @@
1415
from zarr.metadata import ArrayMetadata
1516

1617

17-
@runtime_checkable
18-
class ByteGetter(Protocol):
19-
async def get(self, byte_range: tuple[int, int | None] | None = None) -> BytesLike | None: ...
20-
21-
22-
@runtime_checkable
23-
class ByteSetter(Protocol):
24-
async def get(self, byte_range: tuple[int, int | None] | None = None) -> BytesLike | None: ...
25-
26-
async def set(self, value: BytesLike, byte_range: tuple[int, int] | None = None) -> None: ...
27-
28-
async def delete(self) -> None: ...
29-
30-
3118
CodecInput = TypeVar("CodecInput", bound=np.ndarray | BytesLike)
3219
CodecOutput = TypeVar("CodecOutput", bound=np.ndarray | BytesLike)
3320

src/zarr/abc/store.py

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
from abc import abstractmethod, ABC
22
from collections.abc import AsyncGenerator
3+
from typing import List, Protocol, Tuple, Optional, runtime_checkable
34

4-
from typing import List, Tuple, Optional
5+
from zarr.common import BytesLike
56

67

78
class Store(ABC):
@@ -61,13 +62,13 @@ def supports_writes(self) -> bool:
6162
...
6263

6364
@abstractmethod
64-
async def set(self, key: str, value: bytes) -> None:
65+
async def set(self, key: str, value: BytesLike) -> None:
6566
"""Store a (key, value) pair.
6667
6768
Parameters
6869
----------
6970
key : str
70-
value : bytes
71+
value : BytesLike
7172
"""
7273
...
7374

@@ -88,12 +89,12 @@ def supports_partial_writes(self) -> bool:
8889
...
8990

9091
@abstractmethod
91-
async def set_partial_values(self, key_start_values: List[Tuple[str, int, bytes]]) -> None:
92+
async def set_partial_values(self, key_start_values: list[tuple[str, int, BytesLike]]) -> None:
9293
"""Store values at a given key, starting at byte range_start.
9394
9495
Parameters
9596
----------
96-
key_start_values : list[tuple[str, int, bytes]]
97+
key_start_values : list[tuple[str, int, BytesLike]]
9798
set of key, range_start, values triples, a key may occur multiple times with different
9899
range_starts, range_starts (considering the length of the respective values) must not
99100
specify overlapping ranges for the same key
@@ -145,3 +146,28 @@ def list_dir(self, prefix: str) -> AsyncGenerator[str, None]:
145146
AsyncGenerator[str, None]
146147
"""
147148
...
149+
150+
151+
@runtime_checkable
152+
class ByteGetter(Protocol):
153+
async def get(
154+
self, byte_range: Optional[Tuple[int, Optional[int]]] = None
155+
) -> Optional[BytesLike]: ...
156+
157+
158+
@runtime_checkable
159+
class ByteSetter(Protocol):
160+
async def get(
161+
self, byte_range: Optional[Tuple[int, Optional[int]]] = None
162+
) -> Optional[BytesLike]: ...
163+
164+
async def set(self, value: BytesLike, byte_range: Optional[Tuple[int, int]] = None) -> None: ...
165+
166+
async def delete(self) -> None: ...
167+
168+
169+
async def set_or_delete(byte_setter: ByteSetter, value: BytesLike | None) -> None:
170+
if value is None:
171+
await byte_setter.delete()
172+
else:
173+
await byte_setter.set(value)

0 commit comments

Comments
 (0)