Skip to content

Commit 7b0a4fa

Browse files
authored
Merge branch 'main' into fix-delete-dir-prefix-matching
2 parents dcf6b16 + 1cda981 commit 7b0a4fa

9 files changed

Lines changed: 488 additions & 455 deletions

File tree

changes/4000.misc.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Run all doctests via pytest and fix all broken doctests.

pyproject.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ ignore_errors = true
414414

415415
[tool.pytest.ini_options]
416416
minversion = "7"
417-
testpaths = ["tests", "docs/user-guide"]
417+
testpaths = ["src", "tests", "docs/user-guide"]
418418
log_cli_level = "INFO"
419419
log_level = "INFO"
420420
xfail_strict = true
@@ -430,6 +430,9 @@ addopts = [
430430
"--benchmark-disable", # benchmark routines run as tests without benchmarking instrumentation
431431
"--durations", "10",
432432
"-ra", "--strict-config", "--strict-markers",
433+
"--doctest-modules",
434+
"--ignore=tests/test_regression/scripts",
435+
"--ignore=src/zarr/_cli",
433436
]
434437
filterwarnings = [
435438
"error",

src/zarr/abc/store.py

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -256,12 +256,20 @@ async def _get_bytes(
256256
257257
Examples
258258
--------
259-
>>> store = await MemoryStore.open()
260-
>>> await store.set("data", Buffer.from_bytes(b"hello world"))
261-
>>> data = await store.get_bytes("data", prototype=default_buffer_prototype())
262-
>>> print(data)
259+
>>> async def example():
260+
... from zarr.core.buffer.cpu import Buffer
261+
... from zarr.storage import MemoryStore
262+
...
263+
... store = await MemoryStore.open()
264+
... await store.set("data", Buffer.from_bytes(b"hello world"))
265+
... # No need to specify prototype for MemoryStore
266+
... return await store._get_bytes("data")
267+
268+
>>> import asyncio
269+
>>> asyncio.run(example())
263270
b'hello world'
264271
"""
272+
265273
buffer = await self.get(key, prototype, byte_range)
266274
if buffer is None:
267275
raise FileNotFoundError(key)
@@ -309,10 +317,11 @@ def _get_bytes_sync(
309317
310318
Examples
311319
--------
320+
>>> from zarr.core.buffer.cpu import Buffer
321+
>>> from zarr.storage import MemoryStore
312322
>>> store = MemoryStore()
313-
>>> await store.set("data", Buffer.from_bytes(b"hello world"))
314-
>>> data = store.get_bytes_sync("data", prototype=default_buffer_prototype())
315-
>>> print(data)
323+
>>> store.set_sync("data", Buffer.from_bytes(b"hello world"))
324+
>>> store._get_bytes_sync("data") # No need to specify prototype for MemoryStore
316325
b'hello world'
317326
"""
318327

@@ -358,11 +367,18 @@ async def _get_json(
358367
359368
Examples
360369
--------
361-
>>> store = await MemoryStore.open()
362-
>>> metadata = {"zarr_format": 3, "node_type": "array"}
363-
>>> await store.set("zarr.json", Buffer.from_bytes(json.dumps(metadata).encode()))
364-
>>> data = await store.get_json("zarr.json", prototype=default_buffer_prototype())
365-
>>> print(data)
370+
>>> async def example():
371+
... from zarr.core.buffer.cpu import Buffer
372+
... from zarr.storage import MemoryStore
373+
...
374+
... store = await MemoryStore.open()
375+
... metadata = {"zarr_format": 3, "node_type": "array"}
376+
... await store.set("zarr.json", Buffer.from_bytes(json.dumps(metadata).encode()))
377+
... # No need to specify prototype for MemoryStore
378+
... return await store._get_json("zarr.json")
379+
380+
>>> import asyncio
381+
>>> asyncio.run(example())
366382
{'zarr_format': 3, 'node_type': 'array'}
367383
"""
368384

@@ -414,11 +430,12 @@ def _get_json_sync(
414430
415431
Examples
416432
--------
433+
>>> from zarr.core.buffer.cpu import Buffer
434+
>>> from zarr.storage import MemoryStore
417435
>>> store = MemoryStore()
418436
>>> metadata = {"zarr_format": 3, "node_type": "array"}
419-
>>> store.set("zarr.json", Buffer.from_bytes(json.dumps(metadata).encode()))
420-
>>> data = store.get_json_sync("zarr.json", prototype=default_buffer_prototype())
421-
>>> print(data)
437+
>>> store.set_sync("zarr.json", Buffer.from_bytes(json.dumps(metadata).encode()))
438+
>>> store._get_json_sync("zarr.json") # No need to specify prototype for MemoryStore
422439
{'zarr_format': 3, 'node_type': 'array'}
423440
"""
424441

src/zarr/api/synchronous.py

Lines changed: 29 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1126,63 +1126,45 @@ def from_array(
11261126
--------
11271127
Create an array from an existing Array:
11281128
1129-
```python
1130-
import zarr
1131-
store = zarr.storage.MemoryStore()
1132-
store2 = zarr.storage.LocalStore('example_from_array.zarr')
1133-
arr = zarr.create_array(
1134-
store=store,
1135-
shape=(100,100),
1136-
chunks=(10,10),
1137-
dtype='int32',
1138-
fill_value=0)
1139-
arr2 = zarr.from_array(store2, data=arr, overwrite=True)
1140-
# <Array file://example_from_array.zarr shape=(100, 100) dtype=int32>
1141-
```
1129+
>>> import asyncio
1130+
>>> import zarr
1131+
>>> store = zarr.storage.LocalStore("example_from_array.zarr")
1132+
>>> arr = zarr.create_array(
1133+
... store={},
1134+
... shape=(100,100),
1135+
... chunks=(10,10),
1136+
... dtype="int32",
1137+
... fill_value=0
1138+
... )
1139+
>>> arr2 = zarr.from_array(store, data=arr, overwrite=True)
1140+
>>> arr2
1141+
<Array file://example_from_array.zarr shape=(100, 100) dtype=int32>
1142+
>>> asyncio.run(store.clear()) # Remove files generated by test
11421143
11431144
Create an array from an existing NumPy array:
11441145
1145-
```python
1146-
import zarr
1147-
import numpy as np
1148-
arr3 = zarr.from_array(
1149-
zarr.storage.MemoryStore(),
1150-
data=np.arange(10000, dtype='i4').reshape(100, 100),
1151-
)
1152-
# <Array memory://... shape=(100, 100) dtype=int32>
1153-
```
1146+
>>> import numpy as np
1147+
>>> zarr.from_array({}, data=np.arange(10000, dtype="i4").reshape(100, 100))
1148+
<Array memory://... shape=(100, 100) dtype=int32>
11541149
11551150
Create an array from any array-like object:
11561151
1157-
```python
1158-
import zarr
1159-
arr4 = zarr.from_array(
1160-
zarr.storage.MemoryStore(),
1161-
data=[[1, 2], [3, 4]],
1162-
)
1163-
# <Array memory://... shape=(2, 2) dtype=int64>
1164-
arr4[...]
1165-
# array([[1, 2],[3, 4]])
1166-
```
1152+
>>> arr3 = zarr.from_array({}, data=[[1, 2], [3, 4]])
1153+
>>> arr3
1154+
<Array memory://... shape=(2, 2) dtype=int64>
1155+
>>> arr3[...]
1156+
array([[1, 2], [3, 4]])
11671157
11681158
Create an array from an existing Array without copying the data:
11691159
1170-
```python
1171-
import zarr
1172-
arr4 = zarr.from_array(
1173-
zarr.storage.MemoryStore(),
1174-
data=[[1, 2], [3, 4]],
1175-
)
1176-
arr5 = zarr.from_array(
1177-
zarr.storage.MemoryStore(),
1178-
data=arr4,
1179-
write_data=False,
1180-
)
1181-
# <Array memory://... shape=(2, 2) dtype=int64>
1182-
arr5[...]
1183-
# array([[0, 0],[0, 0]])
1184-
```
1160+
>>> arr4 = zarr.from_array({}, data=[[1, 2], [3, 4]])
1161+
>>> arr5 = zarr.from_array({}, data=arr4, write_data=False)
1162+
>>> arr5
1163+
<Array memory://... shape=(2, 2) dtype=int64>
1164+
>>> arr5[...]
1165+
array([[0, 0], [0, 0]])
11851166
"""
1167+
11861168
return Array(
11871169
sync(
11881170
zarr.core.array.from_array(

src/zarr/codecs/numcodecs/_codecs.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,16 @@
88
import zarr
99
import zarr.codecs.numcodecs as numcodecs
1010
11+
store = zarr.storage.MemoryStore()
1112
array = zarr.create_array(
12-
store="data_numcodecs.zarr",
13-
shape=(1024, 1024),
14-
chunks=(64, 64),
15-
dtype="uint32",
16-
filters=[numcodecs.Delta(dtype="uint32")],
17-
compressors=[numcodecs.BZ2(level=5)],
18-
overwrite=True)
13+
store=store,
14+
shape=(1024, 1024),
15+
chunks=(64, 64),
16+
dtype="uint32",
17+
filters=[numcodecs.Delta(dtype="uint32")],
18+
compressors=[numcodecs.BZ2(level=5)],
19+
overwrite=True
20+
)
1921
array[:] = np.arange(np.prod(array.shape), dtype=array.dtype).reshape(*array.shape)
2022
```
2123

0 commit comments

Comments
 (0)