Skip to content

Commit 11c4de9

Browse files
committed
Update docs to use memory:// urls instead of explicitly creating a store
1 parent 5201654 commit 11c4de9

6 files changed

Lines changed: 32 additions & 27 deletions

File tree

docs/user-guide/arrays.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,14 @@ np.random.seed(0)
1414

1515
```python exec="true" session="arrays" source="above" result="ansi"
1616
import zarr
17-
store = zarr.storage.MemoryStore()
18-
z = zarr.create_array(store=store, shape=(10000, 10000), chunks=(1000, 1000), dtype='int32')
17+
z = zarr.create_array(store="memory://arrays-demo", shape=(10000, 10000), chunks=(1000, 1000), dtype='int32')
1918
print(z)
2019
```
2120

2221
The code above creates a 2-dimensional array of 32-bit integers with 10000 rows
2322
and 10000 columns, divided into chunks where each chunk has 1000 rows and 1000
24-
columns (and so there will be 100 chunks in total). The data is written to a
25-
[`zarr.storage.MemoryStore`][] (e.g. an in-memory dict). See
23+
columns (and so there will be 100 chunks in total). The data is written to an
24+
in-memory store (see [`zarr.storage.MemoryStore`][] for more details). See
2625
[Persistent arrays](#persistent-arrays) for details on storing arrays in other stores,
2726
and see [Data types](data_types.md) for an in-depth look at the data types supported
2827
by Zarr.

docs/user-guide/attributes.md

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,32 @@
33
Zarr arrays and groups support custom key/value attributes, which can be useful for
44
storing application-specific metadata. For example:
55

6-
```python exec="true" session="arrays" source="above" result="ansi"
6+
```python exec="true" session="attributes" source="above" result="ansi"
77
import zarr
8-
store = zarr.storage.MemoryStore()
9-
root = zarr.create_group(store=store)
8+
root = zarr.create_group(store="memory://attributes-demo")
109
root.attrs['foo'] = 'bar'
1110
z = root.create_array(name='zzz', shape=(10000, 10000), dtype='int32')
1211
z.attrs['baz'] = 42
1312
z.attrs['qux'] = [1, 4, 7, 12]
1413
print(sorted(root.attrs))
1514
```
1615

17-
```python exec="true" session="arrays" source="above" result="ansi"
16+
```python exec="true" session="attributes" source="above" result="ansi"
1817
print('foo' in root.attrs)
1918
```
2019

21-
```python exec="true" session="arrays" source="above" result="ansi"
20+
```python exec="true" session="attributes" source="above" result="ansi"
2221
print(root.attrs['foo'])
2322
```
24-
```python exec="true" session="arrays" source="above" result="ansi"
23+
```python exec="true" session="attributes" source="above" result="ansi"
2524
print(sorted(z.attrs))
2625
```
2726

28-
```python exec="true" session="arrays" source="above" result="ansi"
27+
```python exec="true" session="attributes" source="above" result="ansi"
2928
print(z.attrs['baz'])
3029
```
3130

32-
```python exec="true" session="arrays" source="above" result="ansi"
31+
```python exec="true" session="attributes" source="above" result="ansi"
3332
print(z.attrs['qux'])
3433
```
3534

docs/user-guide/consolidated_metadata.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ import zarr
2727
import warnings
2828

2929
warnings.filterwarnings("ignore", category=UserWarning)
30-
store = zarr.storage.MemoryStore()
31-
group = zarr.create_group(store=store)
30+
group = zarr.create_group(store="memory://consolidated-metadata-demo")
3231
print(group)
3332
array = group.create_array(shape=(1,), name='a', dtype='float64')
3433
print(array)
@@ -45,7 +44,7 @@ print(array)
4544
```
4645

4746
```python exec="true" session="consolidated_metadata" source="above" result="ansi"
48-
result = zarr.consolidate_metadata(store)
47+
result = zarr.consolidate_metadata("memory://consolidated-metadata-demo")
4948
print(result)
5049
```
5150

@@ -56,7 +55,7 @@ that can be used.:
5655
from pprint import pprint
5756
import io
5857

59-
consolidated = zarr.open_group(store=store)
58+
consolidated = zarr.open_group(store="memory://consolidated-metadata-demo")
6059
consolidated_metadata = consolidated.metadata.consolidated_metadata.metadata
6160

6261
# Note: pprint can be users without capturing the output regularly
@@ -76,7 +75,7 @@ With nested groups, the consolidated metadata is available on the children, recu
7675
```python exec="true" session="consolidated_metadata" source="above" result="ansi"
7776
child = group.create_group('child', attributes={'kind': 'child'})
7877
grandchild = child.create_group('child', attributes={'kind': 'grandchild'})
79-
consolidated = zarr.consolidate_metadata(store)
78+
consolidated = zarr.consolidate_metadata("memory://consolidated-metadata-demo")
8079

8180
output = io.StringIO()
8281
pprint(consolidated['child'].metadata.consolidated_metadata, stream=output, width=60)

docs/user-guide/gpu.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,8 @@ buffers used internally by Zarr via `enable_gpu()`.
2020
import zarr
2121
import cupy as cp
2222
zarr.config.enable_gpu()
23-
store = zarr.storage.MemoryStore()
2423
z = zarr.create_array(
25-
store=store, shape=(100, 100), chunks=(10, 10), dtype="float32",
24+
store="memory://gpu-demo", shape=(100, 100), chunks=(10, 10), dtype="float32",
2625
)
2726
type(z[:10, :10])
2827
# cupy.ndarray

docs/user-guide/groups.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ To create a group, use the [`zarr.group`][] function:
88

99
```python exec="true" session="groups" source="above" result="ansi"
1010
import zarr
11-
store = zarr.storage.MemoryStore()
12-
root = zarr.create_group(store=store)
11+
root = zarr.create_group(store="memory://groups-demo")
1312
print(root)
1413
```
1514

@@ -105,8 +104,7 @@ Diagnostic information about arrays and groups is available via the `info`
105104
property. E.g.:
106105

107106
```python exec="true" session="groups" source="above" result="ansi"
108-
store = zarr.storage.MemoryStore()
109-
root = zarr.group(store=store)
107+
root = zarr.group(store="memory://diagnostics-demo")
110108
foo = root.create_group('foo')
111109
bar = foo.create_array(name='bar', shape=1000000, chunks=100000, dtype='int64')
112110
bar[:] = 42

src/zarr/storage/_common.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -329,9 +329,15 @@ async def make_store(
329329
return await LocalStore.open(root=store_like, mode=mode, read_only=_read_only)
330330

331331
elif isinstance(store_like, str):
332-
# Check for memory:// URLs first (in-process registry lookup)
332+
# Check for memory:// URLs first
333333
if store_like.startswith("memory://"):
334-
return ManagedMemoryStore.from_url(store_like, read_only=_read_only)
334+
# Parse the URL to extract name and path
335+
url_without_scheme = store_like[len("memory://") :]
336+
parts = url_without_scheme.split("/", 1)
337+
name = parts[0] if parts[0] else None
338+
path = parts[1] if len(parts) > 1 else ""
339+
# Create or get the store - ManagedMemoryStore handles both cases
340+
return ManagedMemoryStore(name=name, path=path, read_only=_read_only)
335341
# Either an FSSpec URI or a local filesystem path
336342
elif _is_fsspec_uri(store_like):
337343
return FsspecStore.from_url(
@@ -411,9 +417,14 @@ async def make_store_path(
411417

412418
elif isinstance(store_like, str) and store_like.startswith("memory://"):
413419
# Handle memory:// URLs specially
414-
# The store itself now handles the path from the URL
420+
# Parse the URL to extract name and path
415421
_read_only = mode == "r"
416-
memory_store = ManagedMemoryStore.from_url(store_like, read_only=_read_only)
422+
url_without_scheme = store_like[len("memory://") :]
423+
parts = url_without_scheme.split("/", 1)
424+
name = parts[0] if parts[0] else None
425+
url_path = parts[1] if len(parts) > 1 else ""
426+
# Create or get the store - ManagedMemoryStore handles both cases
427+
memory_store = ManagedMemoryStore(name=name, path=url_path, read_only=_read_only)
417428
return await StorePath.open(memory_store, path=path_normalized, mode=mode)
418429

419430
else:

0 commit comments

Comments
 (0)