Skip to content

Remove ArrayV2 #1857

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 18 commits into from
May 16, 2024
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
11 changes: 2 additions & 9 deletions src/zarr/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
from __future__ import annotations

from typing import Union

import zarr.codecs # noqa: F401
from zarr.array import Array, AsyncArray
from zarr.array_v2 import ArrayV2
from zarr.config import config # noqa: F401
from zarr.group import AsyncGroup, Group
from zarr.store import (
Expand All @@ -18,19 +15,15 @@
assert not __version__.startswith("0.0.0")


async def open_auto_async(
store: StoreLike,
) -> Union[AsyncArray, AsyncGroup]:
async def open_auto_async(store: StoreLike) -> AsyncArray | AsyncGroup:
store_path = make_store_path(store)
try:
return await AsyncArray.open(store_path)
except KeyError:
return await AsyncGroup.open(store_path)


def open_auto(
store: StoreLike,
) -> Union[Array, ArrayV2, Group]:
def open_auto(store: StoreLike) -> Array | Group:
object = _sync(
open_auto_async(store),
)
Expand Down
17 changes: 2 additions & 15 deletions src/zarr/abc/codec.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from __future__ import annotations

from abc import abstractmethod
from typing import TYPE_CHECKING, Generic, Iterable, Protocol, TypeVar, runtime_checkable
from typing import TYPE_CHECKING, Generic, Iterable, TypeVar

import numpy as np
from zarr.abc.metadata import Metadata
from zarr.abc.store import ByteGetter, ByteSetter
from zarr.common import BytesLike


Expand All @@ -14,20 +15,6 @@
from zarr.metadata import ArrayMetadata


@runtime_checkable
class ByteGetter(Protocol):
async def get(self, byte_range: tuple[int, int | None] | None = None) -> BytesLike | None: ...


@runtime_checkable
class ByteSetter(Protocol):
async def get(self, byte_range: tuple[int, int | None] | None = None) -> BytesLike | None: ...

async def set(self, value: BytesLike, byte_range: tuple[int, int] | None = None) -> None: ...

async def delete(self) -> None: ...


CodecInput = TypeVar("CodecInput", bound=np.ndarray | BytesLike)
CodecOutput = TypeVar("CodecOutput", bound=np.ndarray | BytesLike)

Expand Down
36 changes: 31 additions & 5 deletions src/zarr/abc/store.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from abc import abstractmethod, ABC
from collections.abc import AsyncGenerator
from typing import List, Protocol, Tuple, Optional, runtime_checkable

from typing import List, Tuple, Optional
from zarr.common import BytesLike


class Store(ABC):
Expand Down Expand Up @@ -61,13 +62,13 @@ def supports_writes(self) -> bool:
...

@abstractmethod
async def set(self, key: str, value: bytes) -> None:
async def set(self, key: str, value: BytesLike) -> None:
"""Store a (key, value) pair.

Parameters
----------
key : str
value : bytes
value : BytesLike
"""
...

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

@abstractmethod
async def set_partial_values(self, key_start_values: List[Tuple[str, int, bytes]]) -> None:
async def set_partial_values(self, key_start_values: list[tuple[str, int, BytesLike]]) -> None:
"""Store values at a given key, starting at byte range_start.

Parameters
----------
key_start_values : list[tuple[str, int, bytes]]
key_start_values : list[tuple[str, int, BytesLike]]
set of key, range_start, values triples, a key may occur multiple times with different
range_starts, range_starts (considering the length of the respective values) must not
specify overlapping ranges for the same key
Expand Down Expand Up @@ -145,3 +146,28 @@ def list_dir(self, prefix: str) -> AsyncGenerator[str, None]:
AsyncGenerator[str, None]
"""
...


@runtime_checkable
class ByteGetter(Protocol):
async def get(
self, byte_range: Optional[Tuple[int, Optional[int]]] = None
) -> Optional[BytesLike]: ...


@runtime_checkable
class ByteSetter(Protocol):
async def get(
self, byte_range: Optional[Tuple[int, Optional[int]]] = None
) -> Optional[BytesLike]: ...

async def set(self, value: BytesLike, byte_range: Optional[Tuple[int, int]] = None) -> None: ...

async def delete(self) -> None: ...


async def set_or_delete(byte_setter: ByteSetter, value: BytesLike | None) -> None:
if value is None:
await byte_setter.delete()
else:
await byte_setter.set(value)
Loading