Skip to content

Commit 68a449e

Browse files
authored
Merge branch 'main' into feat/default-buffer
2 parents 281538a + acdd892 commit 68a449e

File tree

4 files changed

+54
-7
lines changed

4 files changed

+54
-7
lines changed

docs/api/zarr/experimental.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
title: experimental
3+
---
4+
5+
Experimental functionality is not stable and may change or be removed at any point.
6+
7+
## Classes
8+
9+
::: zarr.experimental.cache_store

docs/contributing.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,40 @@ Hatch can also be used to serve continuously updating version of the documentati
173173
hatch --env docs run serve
174174
```
175175

176+
#### Adding executable code blocks in the documentation
177+
178+
Zarr uses [Markdown Exec](https://pawamoy.github.io/markdown-exec/usage/) to execute code blocks in Markdown files. Add `exec="on"` to a code block header for it to be executed when the docs are built. For example:
179+
180+
````md
181+
```python exec="on"
182+
print("Hello world")
183+
```
184+
````
185+
186+
Below are other useful options that can be added to the code block. See [Markdown Exec's documentation](https://pawamoy.github.io/markdown-exec/usage/#options-summary) for a full list:
187+
188+
- `source="above"` makes sure the code within the code block is also rendered in the documentation (rather than just the output).
189+
- `session="<name-of-docs-page>"` executes code blocks in a named session reusing previously defined variables.
190+
- `result="ansi"` or `result="html"` to render the output. If the code does not produce output, you should leave off the `result` option to prevent an empty cell from rendering in the docs.
191+
192+
For example:
193+
194+
````md
195+
```python exec="true" session="contributing" source="above" result="ansi"
196+
print("Hello world")
197+
```
198+
````
199+
200+
renders as:
201+
202+
```python exec="true" session="contributing" source="above" result="ansi"
203+
print("Hello world")
204+
```
205+
206+
#### Building documentation without executing code blocks
207+
208+
Sometimes, you may want the documentation to build quicker. You can disable code block execution by commenting out the [markdown-exec](https://github.com/zarr-developers/zarr-python/blob/884a8c91afcc3efe28b3da952be3b85125c453cb/mkdocs.yml#L132 plugin in the mkdocs configuration file). This will make code blocks and cross references render incorrectly (i.e., expect build warnings), but also reduces build time by ~3x. Be sure to undo the commenting out before opening your pull request.
209+
176210
### Changelog
177211

178212
zarr-python uses [towncrier](https://towncrier.readthedocs.io/en/stable/tutorial.html) to manage release notes. Most pull requests should include at least one news fragment describing the changes. To add a release note, you'll need the GitHub issue or pull request number and the type of your change (`feature`, `bugfix`, `doc`, `removal`, `misc`). With that, run `towncrier create` with your development environment, which will prompt you for the issue number, change type, and the news text:

docs/user-guide/experimental.md

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ This section contains documentation for experimental Zarr Python features. The f
44

55
## `CacheStore`
66

7-
Zarr Python 3.1.4 adds `zarr.experimental.cache_store.CacheStore` provides a dual-store caching implementation
7+
Zarr Python 3.1.4 adds [`zarr.experimental.cache_store.CacheStore`][] provides a dual-store caching implementation
88
that can be wrapped around any Zarr store to improve performance for repeated data access.
99
This is particularly useful when working with remote stores (e.g., S3, HTTP) where network
1010
latency can significantly impact data access speed.
@@ -24,7 +24,7 @@ Because the `CacheStore` uses an ordinary Zarr `Store` object as the caching lay
2424
Creating a CacheStore requires both a source store and a cache store. The cache store
2525
can be any Store implementation, providing flexibility in cache persistence:
2626

27-
```python exec="true" session="experimental" source="above" result="ansi"
27+
```python exec="true" session="experimental" source="above"
2828
import zarr
2929
from zarr.storage import LocalStore
3030
import numpy as np
@@ -73,6 +73,7 @@ elapsed_nocache = time.time() - start
7373

7474
# Cache provides speedup for repeated access
7575
speedup = elapsed_nocache / elapsed_cache
76+
print(f"Speedup is {speedup}")
7677
```
7778

7879
Cache effectiveness is particularly pronounced with repeated access to the same data chunks.
@@ -84,7 +85,7 @@ The CacheStore can be configured with several parameters:
8485

8586
**max_size**: Controls the maximum size of cached data in bytes
8687

87-
```python exec="true" session="experimental" source="above" result="ansi"
88+
```python exec="true" session="experimental" source="above"
8889
# 256MB cache with size limit
8990
cache = CacheStore(
9091
store=source_store,
@@ -102,7 +103,7 @@ cache = CacheStore(
102103

103104
**max_age_seconds**: Controls time-based cache expiration
104105

105-
```python exec="true" session="experimental" source="above" result="ansi"
106+
```python exec="true" session="experimental" source="above"
106107
# Cache expires after 1 hour
107108
cache = CacheStore(
108109
store=source_store,
@@ -162,7 +163,7 @@ The `cache_info()` method returns a dictionary with detailed information about t
162163

163164
The CacheStore provides methods for manual cache management:
164165

165-
```python exec="true" session="experimental" source="above" result="ansi"
166+
```python exec="true" session="experimental" source="above"
166167
# Clear all cached data and tracking information
167168
import asyncio
168169
asyncio.run(cached_store.clear_cache())
@@ -192,7 +193,7 @@ and use any store type for the cache backend:
192193

193194
### Local Store with Memory Cache
194195

195-
```python exec="true" session="experimental-memory-cache" source="above" result="ansi"
196+
```python exec="true" session="experimental-memory-cache" source="above"
196197
from zarr.storage import LocalStore, MemoryStore
197198
from zarr.experimental.cache_store import CacheStore
198199
from tempfile import mkdtemp
@@ -209,7 +210,7 @@ cached_store = CacheStore(
209210

210211
### Memory Store with Persistent Cache
211212

212-
```python exec="true" session="experimental-local-cache" source="above" result="ansi"
213+
```python exec="true" session="experimental-local-cache" source="above"
213214
from tempfile import mkdtemp
214215
from zarr.storage import MemoryStore, LocalStore
215216
from zarr.experimental.cache_store import CacheStore
@@ -255,10 +256,12 @@ zarr_array[:] = np.random.random((100, 100))
255256
start = time.time()
256257
data = zarr_array[20:30, 20:30] # First access (cache miss)
257258
first_access = time.time() - start
259+
print(f"First access took {first_access}")
258260

259261
start = time.time()
260262
data = zarr_array[20:30, 20:30] # Second access (cache hit)
261263
second_access = time.time() - start
264+
print(f"Second access took {second_access}")
262265

263266
# Check cache statistics
264267
info = cached_store.cache_info()

mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ nav:
4646
- api/zarr/metadata.md
4747
- api/zarr/registry.md
4848
- api/zarr/storage.md
49+
- api/zarr/experimental.md
4950
- ABC:
5051
- api/zarr/abc/index.md
5152
- api/zarr/abc/buffer.md

0 commit comments

Comments
 (0)