Skip to content

Commit 8af0ce4

Browse files
committed
add docstring for wrapper module
1 parent 269215e commit 8af0ce4

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

src/zarr/core/dtype/wrapper.py

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,25 @@
1+
"""
2+
Wrapper for native array data types.
3+
4+
The `ZDType` class is an abstract base class for wrapping native array data types, e.g. numpy dtypes.
5+
It provides a common interface for working with data types in a way that is independent of the
6+
underlying data type system.
7+
8+
The wrapper class encapsulates a native data type. Instances of the class can be created from a
9+
native data type instance, and a native data type instance can be created from an instance of the
10+
wrapper class.
11+
12+
The wrapper class is responsible for:
13+
- Reversibly serializing a native data type to Zarr V2 or Zarr V3 metadata.
14+
This ensures that the data type can be properly stored and retrieved from array metadata.
15+
- Reversibly serializing scalar values to Zarr V2 or Zarr V3 metadata. This is important for
16+
storing a fill value for an array in a manner that is valid for the data type.
17+
18+
To add support for a new data type in Zarr, you should subclass the wrapper class and adapt its methods
19+
to support your native data type. The wrapper class must be added to a data type registry
20+
(defined elsewhere) before ``create_array`` can properly handle the new data type.
21+
"""
22+
123
from __future__ import annotations
224

325
from abc import ABC, abstractmethod
@@ -17,9 +39,10 @@
1739
# This is the bound for the dtypes that we support. If we support non-numpy dtypes,
1840
# then this bound will need to be widened.
1941
_BaseDType = np.dtype[np.generic]
42+
# These two type parameters are covariant because we want
43+
# x : ZDType[BaseDType, BaseScalar] = ZDType[SubDType, SubScalar]
44+
# to type check
2045
TScalar_co = TypeVar("TScalar_co", bound=_BaseScalar, covariant=True)
21-
# TODO: figure out an interface or protocol that non-numpy dtypes can use
22-
# These two type parameters are covariant because we want isinstance(ZDType[Subclass](), ZDType[BaseDType]) to be True
2346
TDType_co = TypeVar("TDType_co", bound=_BaseDType, covariant=True)
2447

2548

0 commit comments

Comments
 (0)