Skip to content

Commit a213058

Browse files
committed
rename methods
1 parent d70a5e5 commit a213058

File tree

6 files changed

+85
-98
lines changed

6 files changed

+85
-98
lines changed

src/zarr/abc/store.py

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ async def get(
209209
"""
210210
...
211211

212-
async def get_bytes_async(
212+
async def get_bytes(
213213
self, key: str, *, prototype: BufferPrototype, byte_range: ByteRequest | None = None
214214
) -> bytes:
215215
"""
@@ -242,7 +242,7 @@ async def get_bytes_async(
242242
--------
243243
get : Lower-level method that returns a Buffer object.
244244
get_bytes : Synchronous version of this method.
245-
get_json_async : Asynchronous method for retrieving and parsing JSON data.
245+
get_json : Asynchronous method for retrieving and parsing JSON data.
246246
247247
Examples
248248
--------
@@ -257,7 +257,7 @@ async def get_bytes_async(
257257
raise FileNotFoundError(key)
258258
return buffer.to_bytes()
259259

260-
def get_bytes(
260+
def get_bytes_sync(
261261
self, key: str = "", *, prototype: BufferPrototype, byte_range: ByteRequest | None = None
262262
) -> bytes:
263263
"""
@@ -289,7 +289,7 @@ def get_bytes(
289289
290290
Warnings
291291
--------
292-
Do not call this method from async functions. Use ``get_bytes_async()`` instead
292+
Do not call this method from async functions. Use ``get_bytes()`` instead
293293
to avoid blocking the event loop.
294294
295295
See Also
@@ -300,23 +300,22 @@ def get_bytes(
300300
Examples
301301
--------
302302
>>> store = MemoryStore()
303-
>>> store.set("data", Buffer.from_bytes(b"hello world"))
304-
>>> data = store.get_bytes("data", prototype=default_buffer_prototype())
303+
>>> await store.set("data", Buffer.from_bytes(b"hello world"))
304+
>>> data = store.get_bytes_sync("data", prototype=default_buffer_prototype())
305305
>>> print(data)
306306
b'hello world'
307307
"""
308308

309-
return sync(self.get_bytes_async(key, prototype=prototype, byte_range=byte_range))
309+
return sync(self.get_bytes(key, prototype=prototype, byte_range=byte_range))
310310

311-
async def get_json_async(
311+
async def get_json(
312312
self, key: str, *, prototype: BufferPrototype, byte_range: ByteRequest | None = None
313313
) -> Any:
314314
"""
315315
Retrieve and parse JSON data from the store asynchronously.
316316
317317
This is a convenience method that retrieves bytes from the store and
318-
parses them as JSON. Commonly used for reading Zarr metadata files
319-
like ``zarr.json``.
318+
parses them as JSON.
320319
321320
Parameters
322321
----------
@@ -344,31 +343,29 @@ async def get_json_async(
344343
345344
See Also
346345
--------
347-
get_bytes_async : Method for retrieving raw bytes without parsing.
348-
get_json : Synchronous version of this method.
346+
get_bytes : Method for retrieving raw bytes.
347+
get_json_sync : Synchronous version of this method.
349348
350349
Examples
351350
--------
352351
>>> store = await MemoryStore.open()
353352
>>> metadata = {"zarr_format": 3, "node_type": "array"}
354353
>>> await store.set("zarr.json", Buffer.from_bytes(json.dumps(metadata).encode()))
355-
>>> data = await store.get_json_async("zarr.json", prototype=default_buffer_prototype())
354+
>>> data = await store.get_json("zarr.json", prototype=default_buffer_prototype())
356355
>>> print(data)
357356
{'zarr_format': 3, 'node_type': 'array'}
358357
"""
359358

360-
return json.loads(
361-
await self.get_bytes_async(key, prototype=prototype, byte_range=byte_range)
362-
)
359+
return json.loads(await self.get_bytes(key, prototype=prototype, byte_range=byte_range))
363360

364-
def get_json(
361+
def get_json_sync(
365362
self, key: str = "", *, prototype: BufferPrototype, byte_range: ByteRequest | None = None
366363
) -> Any:
367364
"""
368365
Retrieve and parse JSON data from the store synchronously.
369366
370-
This is a synchronous wrapper around ``get_json_async()``. It should only
371-
be called from non-async code. For async contexts, use ``get_json_async()``
367+
This is a synchronous wrapper around ``get_json()``. It should only
368+
be called from non-async code. For async contexts, use ``get_json()``
372369
instead.
373370
374371
Parameters
@@ -397,25 +394,25 @@ def get_json(
397394
398395
Warnings
399396
--------
400-
Do not call this method from async functions. Use ``get_json_async()`` instead
397+
Do not call this method from async functions. Use ``get_json()`` instead
401398
to avoid blocking the event loop.
402399
403400
See Also
404401
--------
405-
get_json_async : Asynchronous version of this method.
406-
get_bytes : Synchronous method for retrieving raw bytes without parsing.
402+
get_json : Asynchronous version of this method.
403+
get_bytes_sync : Synchronous method for retrieving raw bytes without parsing.
407404
408405
Examples
409406
--------
410407
>>> store = MemoryStore()
411408
>>> metadata = {"zarr_format": 3, "node_type": "array"}
412409
>>> store.set("zarr.json", Buffer.from_bytes(json.dumps(metadata).encode()))
413-
>>> data = store.get_json("zarr.json", prototype=default_buffer_prototype())
410+
>>> data = store.get_json_sync("zarr.json", prototype=default_buffer_prototype())
414411
>>> print(data)
415412
{'zarr_format': 3, 'node_type': 'array'}
416413
"""
417414

418-
return sync(self.get_json_async(key, prototype=prototype, byte_range=byte_range))
415+
return sync(self.get_json(key, prototype=prototype, byte_range=byte_range))
419416

420417
@abstractmethod
421418
async def get_partial_values(

src/zarr/storage/_local.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ async def list_dir(self, prefix: str) -> AsyncIterator[str]:
306306
except (FileNotFoundError, NotADirectoryError):
307307
pass
308308

309-
async def get_bytes_async(
309+
async def get_bytes(
310310
self,
311311
key: str = "",
312312
*,
@@ -356,9 +356,9 @@ async def get_bytes_async(
356356
"""
357357
if prototype is None:
358358
prototype = default_buffer_prototype()
359-
return await super().get_bytes_async(key, prototype=prototype, byte_range=byte_range)
359+
return await super().get_bytes(key, prototype=prototype, byte_range=byte_range)
360360

361-
def get_bytes(
361+
def get_bytes_sync(
362362
self,
363363
key: str = "",
364364
*,
@@ -412,9 +412,9 @@ def get_bytes(
412412
"""
413413
if prototype is None:
414414
prototype = default_buffer_prototype()
415-
return super().get_bytes(key, prototype=prototype, byte_range=byte_range)
415+
return super().get_bytes_sync(key, prototype=prototype, byte_range=byte_range)
416416

417-
async def get_json_async(
417+
async def get_json(
418418
self,
419419
key: str = "",
420420
*,
@@ -425,7 +425,7 @@ async def get_json_async(
425425
Retrieve and parse JSON data from the local store asynchronously.
426426
427427
This is a convenience override that makes the ``prototype`` parameter optional
428-
by defaulting to the standard buffer prototype. See the base ``Store.get_json_async``
428+
by defaulting to the standard buffer prototype. See the base ``Store.get_json``
429429
for full documentation.
430430
431431
Parameters
@@ -454,7 +454,7 @@ async def get_json_async(
454454
455455
See Also
456456
--------
457-
Store.get_json_async : Base implementation with full documentation.
457+
Store.get_json : Base implementation with full documentation.
458458
get_json : Synchronous version of this method.
459459
get_bytes_async : Method for retrieving raw bytes without parsing.
460460
@@ -465,15 +465,15 @@ async def get_json_async(
465465
>>> metadata = {"zarr_format": 3, "node_type": "array"}
466466
>>> await store.set("zarr.json", Buffer.from_bytes(json.dumps(metadata).encode()))
467467
>>> # No need to specify prototype for LocalStore
468-
>>> data = await store.get_json_async("zarr.json")
468+
>>> data = await store.get_json("zarr.json")
469469
>>> print(data)
470470
{'zarr_format': 3, 'node_type': 'array'}
471471
"""
472472
if prototype is None:
473473
prototype = default_buffer_prototype()
474-
return await super().get_json_async(key, prototype=prototype, byte_range=byte_range)
474+
return await super().get_json(key, prototype=prototype, byte_range=byte_range)
475475

476-
def get_json(
476+
def get_json_sync(
477477
self,
478478
key: str = "",
479479
*,
@@ -513,12 +513,12 @@ def get_json(
513513
514514
Warnings
515515
--------
516-
Do not call this method from async functions. Use ``get_json_async()`` instead.
516+
Do not call this method from async functions. Use ``get_json()`` instead.
517517
518518
See Also
519519
--------
520520
Store.get_json : Base implementation with full documentation.
521-
get_json_async : Asynchronous version of this method.
521+
get_json : Asynchronous version of this method.
522522
get_bytes : Method for retrieving raw bytes without parsing.
523523
524524
Examples
@@ -534,7 +534,7 @@ def get_json(
534534
"""
535535
if prototype is None:
536536
prototype = default_buffer_prototype()
537-
return super().get_json(key, prototype=prototype, byte_range=byte_range)
537+
return super().get_json_sync(key, prototype=prototype, byte_range=byte_range)
538538

539539
async def move(self, dest_root: Path | str) -> None:
540540
"""

src/zarr/storage/_memory.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ async def list_dir(self, prefix: str) -> AsyncIterator[str]:
175175
for key in keys_unique:
176176
yield key
177177

178-
async def get_bytes_async(
178+
async def get_bytes(
179179
self,
180180
key: str = "",
181181
*,
@@ -225,9 +225,9 @@ async def get_bytes_async(
225225
"""
226226
if prototype is None:
227227
prototype = default_buffer_prototype()
228-
return await super().get_bytes_async(key, prototype=prototype, byte_range=byte_range)
228+
return await super().get_bytes(key, prototype=prototype, byte_range=byte_range)
229229

230-
def get_bytes(
230+
def get_bytes_sync(
231231
self,
232232
key: str = "",
233233
*,
@@ -281,9 +281,9 @@ def get_bytes(
281281
"""
282282
if prototype is None:
283283
prototype = default_buffer_prototype()
284-
return super().get_bytes(key, prototype=prototype, byte_range=byte_range)
284+
return super().get_bytes_sync(key, prototype=prototype, byte_range=byte_range)
285285

286-
async def get_json_async(
286+
async def get_json(
287287
self,
288288
key: str = "",
289289
*,
@@ -294,7 +294,7 @@ async def get_json_async(
294294
Retrieve and parse JSON data from the memory store asynchronously.
295295
296296
This is a convenience override that makes the ``prototype`` parameter optional
297-
by defaulting to the standard buffer prototype. See the base ``Store.get_json_async``
297+
by defaulting to the standard buffer prototype. See the base ``Store.get_json``
298298
for full documentation.
299299
300300
Parameters
@@ -323,7 +323,7 @@ async def get_json_async(
323323
324324
See Also
325325
--------
326-
Store.get_json_async : Base implementation with full documentation.
326+
Store.get_json : Base implementation with full documentation.
327327
get_json : Synchronous version of this method.
328328
get_bytes_async : Method for retrieving raw bytes without parsing.
329329
@@ -334,15 +334,15 @@ async def get_json_async(
334334
>>> metadata = {"zarr_format": 3, "node_type": "array"}
335335
>>> await store.set("zarr.json", Buffer.from_bytes(json.dumps(metadata).encode()))
336336
>>> # No need to specify prototype for MemoryStore
337-
>>> data = await store.get_json_async("zarr.json")
337+
>>> data = await store.get_json("zarr.json")
338338
>>> print(data)
339339
{'zarr_format': 3, 'node_type': 'array'}
340340
"""
341341
if prototype is None:
342342
prototype = default_buffer_prototype()
343-
return await super().get_json_async(key, prototype=prototype, byte_range=byte_range)
343+
return await super().get_json(key, prototype=prototype, byte_range=byte_range)
344344

345-
def get_json(
345+
def get_json_sync(
346346
self,
347347
key: str = "",
348348
*,
@@ -382,12 +382,12 @@ def get_json(
382382
383383
Warnings
384384
--------
385-
Do not call this method from async functions. Use ``get_json_async()`` instead.
385+
Do not call this method from async functions. Use ``get_json()`` instead.
386386
387387
See Also
388388
--------
389389
Store.get_json : Base implementation with full documentation.
390-
get_json_async : Asynchronous version of this method.
390+
get_json : Asynchronous version of this method.
391391
get_bytes : Method for retrieving raw bytes without parsing.
392392
393393
Examples
@@ -403,7 +403,7 @@ def get_json(
403403
"""
404404
if prototype is None:
405405
prototype = default_buffer_prototype()
406-
return super().get_json(key, prototype=prototype, byte_range=byte_range)
406+
return super().get_json_sync(key, prototype=prototype, byte_range=byte_range)
407407

408408

409409
class GpuMemoryStore(MemoryStore):

src/zarr/testing/store.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -534,9 +534,9 @@ async def test_get_bytes_async(self, store: S) -> None:
534534
data = b"hello world"
535535
key = "zarr.json"
536536
await self.set(store, key, self.buffer_cls.from_bytes(data))
537-
assert await store.get_bytes_async(key, prototype=default_buffer_prototype()) == data
537+
assert await store.get_bytes(key, prototype=default_buffer_prototype()) == data
538538
with pytest.raises(FileNotFoundError):
539-
await store.get_bytes_async("nonexistent_key", prototype=default_buffer_prototype())
539+
await store.get_bytes("nonexistent_key", prototype=default_buffer_prototype())
540540

541541
def test_get_bytes_sync(self, store: S) -> None:
542542
"""
@@ -545,17 +545,17 @@ def test_get_bytes_sync(self, store: S) -> None:
545545
data = b"hello world"
546546
key = "zarr.json"
547547
sync(self.set(store, key, self.buffer_cls.from_bytes(data)))
548-
assert store.get_bytes(key, prototype=default_buffer_prototype()) == data
548+
assert store.get_bytes_sync(key, prototype=default_buffer_prototype()) == data
549549

550-
async def test_get_json_async(self, store: S) -> None:
550+
async def test_get_json(self, store: S) -> None:
551551
"""
552552
Test that the get_bytes_async method reads json.
553553
"""
554554
data = {"foo": "bar"}
555555
data_bytes = json.dumps(data).encode("utf-8")
556556
key = "zarr.json"
557557
await self.set(store, key, self.buffer_cls.from_bytes(data_bytes))
558-
assert await store.get_json_async(key, prototype=default_buffer_prototype()) == data
558+
assert await store.get_json(key, prototype=default_buffer_prototype()) == data
559559

560560
def test_get_json_sync(self, store: S) -> None:
561561
"""
@@ -565,7 +565,7 @@ def test_get_json_sync(self, store: S) -> None:
565565
data_bytes = json.dumps(data).encode("utf-8")
566566
key = "zarr.json"
567567
sync(self.set(store, key, self.buffer_cls.from_bytes(data_bytes)))
568-
assert store.get_json(key, prototype=default_buffer_prototype()) == data
568+
assert store.get_json_sync(key, prototype=default_buffer_prototype()) == data
569569

570570

571571
class LatencyStore(WrapperStore[Store]):

0 commit comments

Comments
 (0)