1- Array Data Types
1+ Array data types
22================
33
44Zarr's Data Type Model
@@ -179,7 +179,7 @@ We do this with an abstract Zarr data type class: `ZDType <../api/zarr/dtype/ind
179179which provides Zarr V2 and Zarr V3 compatibility routines for "native" data types.
180180
181181In this context, a "native" data type is a Python class, typically defined in another library, that
182- models an array's data type. For example, ``numpy .dtypes.UInt8DType `` is a native data type defined in NumPy.
182+ models an array's data type. For example, ``np .dtypes.UInt8DType `` is a native data type defined in NumPy.
183183Zarr Python wraps the NumPy ``uint8 `` with a ``ZDType `` instance called
184184`UInt8 <../api/zarr/dtype/index.html#zarr.dtype.ZDType >`_.
185185
@@ -195,14 +195,19 @@ API for the following operations:
195195- Encoding and decoding a scalar value to and from Zarr V2 and Zarr V3 array metadata
196196- Casting a Python object to a scalar value consistent with the data type
197197
198- The following section lists the data types built into Zarr Python.
198+ List of data types
199+ ^^^^^^^^^^^^^^^^^^
199200
200- Boolean Types
201- ^^^^^^^^^^^^^
201+ The following section lists the data types built in to Zarr Python. With a few exceptions, Zarr
202+ Python supports nearly all of the data types in NumPy. If you need a data type that is not listed
203+ here, it's possible to create it yourself: see :ref: `adding-new-data-types `.
204+
205+ Boolean
206+ """""""
202207- `Boolean <../api/zarr/dtype/index.html#zarr.dtype.Bool >`_
203208
204- Integral Types
205- ^^^^^^^^^^^^^^
209+ Integral
210+ """"""""
206211- `Signed 8-bit integer <../api/zarr/dtype/index.html#zarr.dtype.Int8 >`_
207212- `Signed 16-bit integer <../api/zarr/dtype/index.html#zarr.dtype.Int16 >`_
208213- `Signed 32-bit integer <../api/zarr/dtype/index.html#zarr.dtype.Int32 >`_
@@ -212,27 +217,38 @@ Integral Types
212217- `Unsigned 32-bit integer <../api/zarr/dtype/index.html#zarr.dtype.UInt32 >`_
213218- `Unsigned 64-bit integer <../api/zarr/dtype/index.html#zarr.dtype.UInt64 >`_
214219
215- Floating-Point Types
216- ^^^^^^^^^^^^^^^^^^^^
220+ Floating-point
221+ """"""""""""""
217222- `16-bit floating-point <../api/zarr/dtype/index.html#zarr.dtype.Float16 >`_
218223- `32-bit floating-point <../api/zarr/dtype/index.html#zarr.dtype.Float32 >`_
219224- `64-bit floating-point <../api/zarr/dtype/index.html#zarr.dtype.Float64 >`_
220225- `64-bit complex floating-point <../api/zarr/dtype/index.html#zarr.dtype.Complex64 >`_
221226- `128-bit complex floating-point <../api/zarr/dtype/index.html#zarr.dtype.Complex128 >`_
222227
223- String Types
224- ^^^^^^^^^^^^
228+ String
229+ """"""
225230- `Fixed-length UTF-32 string <../api/zarr/dtype/index.html#zarr.dtype.FixedLengthUTF32 >`_
226231- `Variable-length UTF-8 string <../api/zarr/dtype/index.html#zarr.dtype.VariableLengthUTF8 >`_
227232
228- Byte String Types
229- ^^^^^^^^^^^^^^^^^
233+ Bytes
234+ """""
230235- `Fixed-length null-terminated bytes <../api/zarr/dtype/index.html#zarr.dtype.NullTerminatedBytes >`_
231236- `Fixed-length raw bytes <../api/zarr/dtype/index.html#zarr.dtype.RawBytes >`_
232237- `Variable-length bytes <../api/zarr/dtype/index.html#zarr.dtype.VariableLengthBytes >`_
233238
239+ Temporal
240+ """"""""
241+ - `DateTime64 <../api/zarr/dtype/index.html#zarr.dtype.DateTime64 >`_
242+ - `TimeDelta64 <../api/zarr/dtype/index.html#zarr.dtype.TimeDelta64 >`_
243+
244+ Struct-like
245+ """""""""""
246+ - `Structured <../api/zarr/dtype/index.html#zarr.dtype.Structured >`_
247+
234248Example Usage
235- ~~~~~~~~~~~~~
249+ ^^^^^^^^^^^^^
250+
251+ This section will demonstrates the basic usage of Zarr data types.
236252
237253Create a ``ZDType `` from a native data type:
238254
@@ -296,8 +312,10 @@ Deserialize a scalar value from JSON:
296312 >> > scalar_value = int8.from_json_scalar(42 , zarr_format = 3 )
297313 >> > assert scalar_value == np.int8(42 )
298314
315+ .. _adding-new-data-types :
316+
299317Adding New Data Types
300- ~~~~~~~~~~~~~~~~~~~~~
318+ ^^^^^^^^^^^^^^^^^^^^^
301319
302320Each Zarr data type is a separate Python class that inherits from
303321`ZDType <../api/zarr/dtype/index.html#zarr.dtype.ZDType >`_. You can define a custom data type by
@@ -311,7 +329,7 @@ Python project directory.
311329 :language: python
312330
313331Data Type Resolution
314- ~~~~~~~~~~~~~~~~~~~~
332+ ^^^^^^^^^^^^^^^^^^^^
315333
316334Although Zarr Python uses a different data type model from NumPy, you can still define a Zarr array
317335with a NumPy data type object:
@@ -338,7 +356,7 @@ data type as its ``dtype`` attribute:
338356.. code-block :: python
339357
340358 >> > type (a.dtype)
341- < class ' numpy .dtypes.Int64DType' >
359+ < class ' np .dtypes.Int64DType' >
342360
343361 But if we inspect the metadata for the array, we can see the Zarr data type object:
344362
@@ -379,8 +397,9 @@ a static lookup table, Zarr Python relies on a dynamic approach to data type res
379397Zarr Python defines a collection of Zarr data types. This collection, called a "data type registry,"
380398is essentially a dictionary where the keys are strings (a canonical name for each data type), and the
381399values are the data type classes themselves. Dynamic data type resolution entails iterating over
382- these data type classes, invoking a special class constructor defined on each one, and returning a
383- concrete data type instance if and only if exactly one of those constructor invocations is successful.
400+ these data type classes, invoking that class' `from_native_dtype <#api/dtype/ZDType.from_native_dtype >`_
401+ method, and returning a concrete data type instance if and only if exactly one of those constructor
402+ invocations is successful.
384403
385404In plain language, we take some user input, like a NumPy data type, offer it to all the
386405known data type classes, and return an instance of the one data type class that can accept that user input.
0 commit comments