Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changes/3502.doc.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Reorganize the top-level `examples` directory to give each example its own sub-directory. Adds content to the docs for each example.
10 changes: 2 additions & 8 deletions docs/user-guide/data_types.md
Original file line number Diff line number Diff line change
Expand Up @@ -298,14 +298,8 @@ assert scalar_value == np.int8(42)
Each Zarr data type is a separate Python class that inherits from
[ZDType][zarr.dtype.ZDType]. You can define a custom data type by
writing your own subclass of [ZDType][zarr.dtype.ZDType] and adding
your data type to the data type registry. A complete example of this process is included below.

The source code for this example can be found in the `examples/custom_dtype.py` file in the Zarr
Python project directory.

```python
--8<-- "examples/custom_dtype.py"
```
your data type to the data type registry. To see an executable demonstration
of this process, see the [`custom_dtype` example](../user-guide/examples/custom_dtype.md).

### Data Type Resolution

Expand Down
7 changes: 7 additions & 0 deletions docs/user-guide/examples/custom_dtype.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
--8<-- "examples/custom_dtype/README.md"

## Source Code

```python
--8<-- "examples/custom_dtype/custom_dtype.py"
```
44 changes: 44 additions & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Zarr Python Examples

This directory contains complete, runnable examples demonstrating various features and use cases of Zarr Python.

## Directory Structure

Each example is organized in its own subdirectory with the following structure:

```
examples/
├── example_name/
│ ├── README.md # Documentation for the example
│ └── example_name.py # Python source code
└── ...
```

## Adding New Examples

To add a new example:

1. Create a new subdirectory: `examples/my_example/`
2. Add your Python code: `examples/my_example/my_example.py`
3. Create documentation: `examples/my_example/README.md`
4. Create a documentation page at `docs/user-guide/examples/my_example.md`. The documentation page should simply link to the `README.md` and the source code, e.g.:

````
# docs/user-guide/examples/my_example.md
--8<-- "examples/my_example/README.md"

## Source Code

```python
--8<-- "examples/my_example/my_example.py"
```
````
5. Update `mkdocs.yml` to include the new example in the navigation.

### Example README.md Format

Your README.md should include:

- A title (`# Example Name`)
- Description of what the example demonstrates
- Instructions for running the example
22 changes: 22 additions & 0 deletions examples/custom_dtype/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Custom Data Type Example

This example demonstrates how to extend Zarr Python by defining a new data type.

The example shows how to:

- Define a custom `ZDType` class for the `int2` data type from [`ml_dtypes`](https://pypi.org/project/ml-dtypes/)
- Implement all required methods for serialization and deserialization
- Register the custom data type with Zarr's registry
- Create and use arrays with the custom data type in both Zarr v2 and v3 formats

## Running the Example

```bash
python examples/custom_dtype/custom_dtype.py
```

Or run with uv:

```bash
uv run examples/custom_dtype/custom_dtype.py
```
File renamed without changes.
2 changes: 2 additions & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ nav:
- user-guide/extending.md
- user-guide/gpu.md
- user-guide/consolidated_metadata.md
- Examples:
- user-guide/examples/custom_dtype.md
- user-guide/experimental.md
- API Reference:
- api/index.md
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ dependencies = [
features = ['docs', 'remote']

[tool.hatch.envs.docs.scripts]
serve = "mkdocs serve"
serve = "mkdocs serve --watch src"
build = "mkdocs build"
check = "mkdocs build --strict"
readthedocs = "rm -rf $READTHEDOCS_OUTPUT/html && cp -r site $READTHEDOCS_OUTPUT/html"
Expand Down