Skip to content

Commit 1926e19

Browse files
committed
fixups
1 parent 5e0ffe8 commit 1926e19

File tree

20 files changed

+61
-20
lines changed

20 files changed

+61
-20
lines changed

docs/guide/storage.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,5 +97,13 @@ Zarr-Python :class:`zarr.abc.store.Store` API is meant to be extended. The Store
9797
Class includes all of the methods needed to be a fully operational store in Zarr Python.
9898
Zarr also provides a test harness for custom stores: :class:`zarr.testing.store.StoreTests`.
9999

100+
``Store.get``
101+
~~~~~~~~~~~~~
102+
103+
The ``prototype`` keyword of :func:`zarr.abc.store.Store.get` uses a default of
104+
``None``. When given ``None``, implementations should use
105+
:func:`zarr.buffer.default_buffer_prototype` to look up the prototype users have
106+
configured.
107+
100108
.. _Zip Store Specification: https://github.com/zarr-developers/zarr-specs/pull/311
101109
.. _Fsspec: https://zarr-specs.readthedocs.io/en/latest/v3/core/v3.0.html#consolidated-metadata

src/zarr/abc/store.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ def __eq__(self, value: object) -> bool:
199199
async def get(
200200
self,
201201
key: str,
202-
prototype: BufferPrototype,
202+
prototype: BufferPrototype | None = None,
203203
byte_range: ByteRangeRequest | None = None,
204204
) -> Buffer | None:
205205
"""Retrieve the value associated with a given key.
@@ -208,6 +208,9 @@ async def get(
208208
----------
209209
key : str
210210
byte_range : tuple[int | None, int | None], optional
211+
prototype: BufferPrototype, optional
212+
The prototype giving the buffer classes to use for buffers and nbuffers.
213+
By default, :func:`zarr.buffer.default_buffer_prototype` is used.
211214
212215
Returns
213216
-------

src/zarr/buffer.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from zarr.core.buffer import default_buffer_prototype
2+
3+
__all__ = [
4+
"default_buffer_prototype",
5+
]

src/zarr/storage/local.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
from zarr.abc.store import ByteRangeRequest, Store
1111
from zarr.core.buffer import Buffer
12+
from zarr.core.buffer.core import default_buffer_prototype
1213
from zarr.core.common import concurrent_map
1314

1415
if TYPE_CHECKING:
@@ -143,10 +144,12 @@ def __eq__(self, other: object) -> bool:
143144
async def get(
144145
self,
145146
key: str,
146-
prototype: BufferPrototype,
147+
prototype: BufferPrototype | None = None,
147148
byte_range: tuple[int | None, int | None] | None = None,
148149
) -> Buffer | None:
149150
# docstring inherited
151+
if prototype is None:
152+
prototype = default_buffer_prototype()
150153
if not self._is_open:
151154
await self._open()
152155
assert isinstance(key, str)

src/zarr/storage/logging.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ def __eq__(self, other: object) -> bool:
159159
async def get(
160160
self,
161161
key: str,
162-
prototype: BufferPrototype,
162+
prototype: BufferPrototype | None = None,
163163
byte_range: tuple[int | None, int | None] | None = None,
164164
) -> Buffer | None:
165165
# docstring inherited

src/zarr/storage/memory.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
from zarr.abc.store import ByteRangeRequest, Store
66
from zarr.core.buffer import Buffer, gpu
7+
from zarr.core.buffer.core import default_buffer_prototype
78
from zarr.core.common import concurrent_map
89
from zarr.storage._utils import _normalize_interval_index
910

@@ -79,10 +80,12 @@ def __eq__(self, other: object) -> bool:
7980
async def get(
8081
self,
8182
key: str,
82-
prototype: BufferPrototype,
83+
prototype: BufferPrototype | None = None,
8384
byte_range: tuple[int | None, int | None] | None = None,
8485
) -> Buffer | None:
8586
# docstring inherited
87+
if prototype is None:
88+
prototype = default_buffer_prototype()
8689
if not self._is_open:
8790
await self._open()
8891
assert isinstance(key, str)

src/zarr/storage/remote.py

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

3-
from typing import TYPE_CHECKING, Any, Self, cast
3+
from typing import TYPE_CHECKING, Any, Self
44

55
import fsspec
66

77
from zarr.abc.store import ByteRangeRequest, Store
8+
from zarr.core.buffer.core import default_buffer_prototype
89
from zarr.storage.common import _dereference_path
910

1011
if TYPE_CHECKING:
@@ -175,10 +176,12 @@ def __eq__(self, other: object) -> bool:
175176
async def get(
176177
self,
177178
key: str,
178-
prototype: BufferPrototype,
179+
prototype: BufferPrototype | None = None,
179180
byte_range: ByteRangeRequest | None = None,
180181
) -> Buffer | None:
181182
# docstring inherited
183+
if prototype is None:
184+
prototype = default_buffer_prototype()
182185
if not self._is_open:
183186
await self._open()
184187
path = _dereference_path(self.path, key)
@@ -312,5 +315,5 @@ async def getsize(self, key: str) -> int:
312315
# Not all filesystems support size. Fall back to reading the entire object
313316
return await super().getsize(key)
314317
else:
315-
# fsspec doesn't have typing. We'll need to assume this is correct.
316-
return cast(int, size)
318+
# fsspec doesn't have typing. We'll need to assume or verify this is true
319+
return int(size)

src/zarr/storage/zip.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
from zarr.abc.store import ByteRangeRequest, Store
1111
from zarr.core.buffer import Buffer, BufferPrototype
12+
from zarr.core.buffer.core import default_buffer_prototype
1213

1314
if TYPE_CHECKING:
1415
from collections.abc import AsyncGenerator, Iterable
@@ -166,11 +167,13 @@ def _get(
166167
async def get(
167168
self,
168169
key: str,
169-
prototype: BufferPrototype,
170+
prototype: BufferPrototype | None = None,
170171
byte_range: ByteRangeRequest | None = None,
171172
) -> Buffer | None:
172173
# docstring inherited
173174
assert isinstance(key, str)
175+
if prototype is None:
176+
prototype = default_buffer_prototype()
174177

175178
with self._lock:
176179
return self._get(key, prototype=prototype, byte_range=byte_range)

src/zarr/testing/store.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,15 @@ async def test_get(
121121
expected = data_buf[start : start + length]
122122
assert_bytes_equal(observed, expected)
123123

124+
async def test_get_default_prototype(self, store: S) -> None:
125+
key = "c/0"
126+
data = b"\x01\x02\x03\x04"
127+
data_buf = self.buffer_cls.from_bytes(data)
128+
await self.set(store, key, data_buf)
129+
observed = await store.get(key)
130+
expected = data_buf[:]
131+
assert_bytes_equal(observed, expected)
132+
124133
async def test_get_many(self, store: S) -> None:
125134
"""
126135
Ensure that multiple keys can be retrieved at once with the _get_many method.

tests/test_codecs/test_blosc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55

66
from zarr import AsyncArray
77
from zarr.abc.store import Store
8+
from zarr.buffer import default_buffer_prototype
89
from zarr.codecs import BloscCodec, BytesCodec, ShardingCodec
9-
from zarr.core.buffer import default_buffer_prototype
1010
from zarr.storage.common import StorePath
1111

1212

0 commit comments

Comments
 (0)