Skip to content

Commit 546ed6b

Browse files
committed
Use doctests for storage.rst
1 parent f42c176 commit 546ed6b

File tree

1 file changed

+44
-47
lines changed

1 file changed

+44
-47
lines changed

docs/user-guide/storage.rst

Lines changed: 44 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,26 @@ Implicit Store Creation
1616
-----------------------
1717

1818
In most cases, it is not required to create a ``Store`` object explicitly. Passing a string
19-
to Zarr's top level API will result in the store being created automatically.
20-
21-
.. ipython:: python
22-
23-
import zarr
24-
25-
# Implicitly create a writable LocalStore
26-
zarr.open_group("data/foo/bar", mode="w")
27-
28-
# Implicitly create a read-only FsspecStore
29-
zarr.open_group(
30-
"s3://noaa-nwm-retro-v2-zarr-pds",
31-
mode="r",
32-
storage_options={"anon": True}
33-
)
34-
35-
# Implicitly creates a MemoryStore
36-
data = {}
37-
zarr.open_group(data, mode="w")
19+
to Zarr's top level API will result in the store being created automatically.:
20+
21+
>>> import zarr
22+
>>>
23+
>>> # Implicitly create a writable LocalStore
24+
>>> zarr.open_group("data/foo/bar", mode="w")
25+
<Group file://data/foo/bar>
26+
>>>
27+
>>> # Implicitly create a read-only FsspecStore
28+
>>> zarr.open_group(
29+
... "s3://noaa-nwm-retro-v2-zarr-pds",
30+
... mode="r",
31+
... storage_options={"anon": True}
32+
... )
33+
<Group <FsspecStore(S3FileSystem, noaa-nwm-retro-v2-zarr-pds)>>
34+
>>>
35+
>>> # Implicitly creates a MemoryStore
36+
>>> data = {}
37+
>>> zarr.open_group(data, mode="w")
38+
<Group memory://...>
3839

3940
Explicit Store Creation
4041
-----------------------
@@ -47,25 +48,23 @@ Local Store
4748
~~~~~~~~~~~
4849

4950
The :class:`zarr.storage.LocalStore` stores data in a nested set of directories on a local
50-
filesystem.
51+
filesystem.:
5152

52-
.. ipython:: python
53-
54-
store = zarr.storage.LocalStore("data/foo/bar", read_only=True)
55-
# TODO: replace with create_group after #2463
56-
zarr.open(store=store, mode='r')
53+
>>> store = zarr.storage.LocalStore("data/foo/bar", read_only=True)
54+
>>> # TODO: replace with create_group after #2463
55+
>>> zarr.open(store=store, mode='r')
56+
<Group file://data/foo/bar>
5757

5858
Zip Store
5959
~~~~~~~~~
6060

6161
The :class:`zarr.storage.ZipStore` stores the contents of a Zarr hierarchy in a single
62-
Zip file. The `Zip Store specification`_ is currently in draft form.
63-
64-
.. ipython:: python
62+
Zip file. The `Zip Store specification`_ is currently in draft form.:
6563

66-
store = zarr.storage.ZipStore("data.zip", mode="w")
67-
# TODO: replace with create_array after #2463
68-
zarr.open(store=store, shape=(2,))
64+
>>> store = zarr.storage.ZipStore("data.zip", mode="w")
65+
>>> # TODO: replace with create_array after #2463
66+
>>> zarr.open(store=store, shape=(2,))
67+
<Array zip://data.zip shape=(2,) dtype=float64>
6968

7069
Remote Store
7170
~~~~~~~~~~~~
@@ -75,29 +74,27 @@ logical layout as the ``LocalStore``, except the store is assumed to be on a rem
7574
such as cloud object storage (e.g. AWS S3, Google Cloud Storage, Azure Blob Store). The
7675
:class:`zarr.storage.FsspecStore` is backed by `fsspec`_ and can support any backend
7776
that implements the `AbstractFileSystem <https://filesystem-spec.readthedocs.io/en/stable/api.html#fsspec.spec.AbstractFileSystem>`_
78-
API. ``storage_options`` can be used to configure the fsspec backend.
77+
API. ``storage_options`` can be used to configure the fsspec backend.:
7978

80-
.. ipython:: python
81-
82-
store = zarr.storage.FsspecStore.from_url(
83-
"s3://noaa-nwm-retro-v2-zarr-pds",
84-
read_only=True,
85-
storage_options={"anon": True}
86-
)
87-
zarr.open_group(store=store, mode='r')
79+
>>> store = zarr.storage.FsspecStore.from_url(
80+
... "s3://noaa-nwm-retro-v2-zarr-pds",
81+
... read_only=True,
82+
... storage_options={"anon": True}
83+
... )
84+
>>> zarr.open_group(store=store, mode='r')
85+
<Group <FsspecStore(S3FileSystem, noaa-nwm-retro-v2-zarr-pds)>>
8886

8987
Memory Store
9088
~~~~~~~~~~~~
9189

9290
The :class:`zarr.storage.MemoryStore` a in-memory store that allows for serialization of
93-
Zarr data (metadata and chunks) to a dictionary.
94-
95-
.. ipython:: python
91+
Zarr data (metadata and chunks) to a dictionary.:
9692

97-
data = {}
98-
store = zarr.storage.MemoryStore(data)
99-
# TODO: replace with create_array after #2463
100-
zarr.open(store=store, shape=(2, ))
93+
>>> data = {}
94+
>>> store = zarr.storage.MemoryStore(data)
95+
>>> # TODO: replace with create_array after #2463
96+
>>> zarr.open(store=store, shape=(2, ))
97+
<Array memory://... shape=(2,) dtype=float64>
10198

10299
Developing custom stores
103100
------------------------

0 commit comments

Comments
 (0)