|
| 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 | + |
1 | 23 | from __future__ import annotations |
2 | 24 |
|
3 | 25 | from abc import ABC, abstractmethod |
|
17 | 39 | # This is the bound for the dtypes that we support. If we support non-numpy dtypes, |
18 | 40 | # then this bound will need to be widened. |
19 | 41 | _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 |
20 | 45 | 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 |
23 | 46 | TDType_co = TypeVar("TDType_co", bound=_BaseDType, covariant=True) |
24 | 47 |
|
25 | 48 |
|
|
0 commit comments