Skip to content

Commit 0639696

Browse files
committed
document and export typeddicts, move dtype docs to an advanced section
1 parent b4a114d commit 0639696

14 files changed

Lines changed: 778 additions & 371 deletions

File tree

docs/user-guide/arrays.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ The code above creates a 2-dimensional array of 32-bit integers with 10000 rows
2323
and 10000 columns, divided into chunks where each chunk has 1000 rows and 1000
2424
columns (and so there will be 100 chunks in total). The data is written to a
2525
:class:`zarr.storage.MemoryStore` (e.g. an in-memory dict). See
26-
:ref:`user-guide-persist` for details on storing arrays in other stores.
26+
:ref:`user-guide-persist` for details on storing arrays in other stores, and see
27+
:ref:`user-guide-data-types` for an in-depth look at the data types supported by Zarr.
2728

2829
For a complete list of array creation routines see the :mod:`zarr`
2930
module documentation.

docs/user-guide/data_types.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
.. _user-guide-data-types:
2+
13
Array data types
24
================
35

docs/user-guide/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ User guide
88

99
installation
1010
arrays
11-
data_types
1211
groups
1312
attributes
1413
storage
@@ -21,6 +20,7 @@ Advanced Topics
2120
.. toctree::
2221
:maxdepth: 1
2322

23+
data_types
2424
performance
2525
consolidated_metadata
2626
extending

src/zarr/core/dtype/__init__.py

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,28 @@
77
DTypeJSON,
88
)
99
from zarr.core.dtype.npy.bool import Bool
10-
from zarr.core.dtype.npy.bytes import NullTerminatedBytes, RawBytes, VariableLengthBytes
10+
from zarr.core.dtype.npy.bytes import (
11+
NullTerminatedBytes,
12+
NullterminatedBytesJSON_V2,
13+
NullTerminatedBytesJSON_V3,
14+
RawBytes,
15+
RawBytesJSON_V2,
16+
RawBytesJSON_V3,
17+
VariableLengthBytes,
18+
VariableLengthBytesJSON_V2,
19+
)
1120
from zarr.core.dtype.npy.complex import Complex64, Complex128
1221
from zarr.core.dtype.npy.float import Float16, Float32, Float64
1322
from zarr.core.dtype.npy.int import Int8, Int16, Int32, Int64, UInt8, UInt16, UInt32, UInt64
14-
from zarr.core.dtype.npy.structured import (
15-
Structured,
23+
from zarr.core.dtype.npy.structured import Structured, StructuredJSON_V2, StructuredJSON_V3
24+
from zarr.core.dtype.npy.time import (
25+
DateTime64,
26+
DateTime64JSON_V2,
27+
DateTime64JSON_V3,
28+
TimeDelta64,
29+
TimeDelta64JSON_V2,
30+
TimeDelta64JSON_V3,
1631
)
17-
from zarr.core.dtype.npy.time import DateTime64, TimeDelta64
1832

1933
if TYPE_CHECKING:
2034
from zarr.core.common import ZarrFormat
@@ -27,7 +41,10 @@
2741
from zarr.core.common import JSON
2842
from zarr.core.dtype.npy.string import (
2943
FixedLengthUTF32,
44+
FixedLengthUTF32JSON_V2,
45+
FixedLengthUTF32JSON_V3,
3046
VariableLengthUTF8,
47+
VariableLengthUTF8JSON_V2,
3148
)
3249
from zarr.core.dtype.registry import DataTypeRegistry
3350
from zarr.core.dtype.wrapper import TBaseDType, TBaseScalar, ZDType
@@ -39,7 +56,11 @@
3956
"DataTypeRegistry",
4057
"DataTypeValidationError",
4158
"DateTime64",
59+
"DateTime64JSON_V2",
60+
"DateTime64JSON_V3",
4261
"FixedLengthUTF32",
62+
"FixedLengthUTF32JSON_V2",
63+
"FixedLengthUTF32JSON_V3",
4364
"Float16",
4465
"Float32",
4566
"Float64",
@@ -48,18 +69,28 @@
4869
"Int32",
4970
"Int64",
5071
"NullTerminatedBytes",
72+
"NullTerminatedBytesJSON_V3",
73+
"NullterminatedBytesJSON_V2",
5174
"RawBytes",
75+
"RawBytesJSON_V2",
76+
"RawBytesJSON_V3",
5277
"Structured",
78+
"StructuredJSON_V2",
79+
"StructuredJSON_V3",
5380
"TBaseDType",
5481
"TBaseScalar",
5582
"TimeDelta64",
5683
"TimeDelta64",
84+
"TimeDelta64JSON_V2",
85+
"TimeDelta64JSON_V3",
5786
"UInt8",
5887
"UInt16",
5988
"UInt32",
6089
"UInt64",
6190
"VariableLengthBytes",
91+
"VariableLengthBytesJSON_V2",
6292
"VariableLengthUTF8",
93+
"VariableLengthUTF8JSON_V2",
6394
"ZDType",
6495
"data_type_registry",
6596
"parse_data_type",

src/zarr/core/dtype/npy/bool.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@ class Bool(ZDType[np.dtypes.BoolDType, np.bool_], HasItemSize):
3737
dtype_cls : ClassVar[type[np.dtypes.BoolDType]] = np.dtypes.BoolDType
3838
The NumPy dtype class.
3939
40-
Notes
41-
-----
40+
References
41+
----------
4242
This class implements the boolean data type defined in Zarr V2 and V3.
43-
You can read the formal specification of that data type in the respective
44-
`specification document <https://zarr-specs.readthedocs.io/en/latest/specs.html>`_
43+
44+
See the `Zarr V2 <https://github.com/zarr-developers/zarr-specs/blob/main/docs/v2/v2.0.rst#data-type-encoding>`_ and `Zarr V3 <https://github.com/zarr-developers/zarr-specs/blob/main/docs/v3/data-types/index.rst>`_ specification documents for details.
4545
"""
4646

4747
_zarr_v3_name: ClassVar[Literal["bool"]] = "bool"
@@ -112,7 +112,7 @@ def _check_json_v2(
112112
@classmethod
113113
def _check_json_v3(cls, data: DTypeJSON) -> TypeGuard[Literal["bool"]]:
114114
"""
115-
Check that the input is a valid JSON representation of a Bool in Zarr V3 format.
115+
Check that the input is a valid JSON representation of this class in Zarr V3.
116116
117117
Parameters
118118
----------
@@ -144,7 +144,7 @@ def _from_json_v2(cls, data: DTypeJSON) -> Self:
144144
Raises
145145
------
146146
DataTypeValidationError
147-
If the input JSON is not a valid representation of a Bool.
147+
If the input JSON is not a valid representation of this class.
148148
"""
149149
if cls._check_json_v2(data):
150150
return cls()
@@ -169,7 +169,7 @@ def _from_json_v3(cls: type[Self], data: DTypeJSON) -> Self:
169169
Raises
170170
------
171171
DataTypeValidationError
172-
If the input JSON is not a valid representation of a Bool.
172+
If the input JSON is not a valid representation of this class.
173173
"""
174174
if cls._check_json_v3(data):
175175
return cls()

0 commit comments

Comments
 (0)