Skip to content

Commit 834682a

Browse files
committed
docstring for parse_data_type
1 parent 5337d17 commit 834682a

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

src/zarr/core/dtype/__init__.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,32 @@ def parse_data_type(
189189
) -> ZDType[TBaseDType, TBaseScalar]:
190190
"""
191191
Interpret the input as a ZDType instance.
192+
193+
Parameters
194+
----------
195+
dtype_spec : ZDTypeLike
196+
The input to be interpreted as a ZDType instance. This could be a native data type
197+
(e.g., a NumPy data type), a Python object that can be converted into a native data type,
198+
a ZDType instance (in which case the input is returned unchanged), or a JSON object
199+
representation of a data type.
200+
zarr_format : ZarrFormat
201+
The zarr format version.
202+
203+
Returns
204+
-------
205+
ZDType[TBaseDType, TBaseScalar]
206+
The ZDType instance corresponding to the input.
207+
208+
Examples
209+
--------
210+
>>> from zarr.dtype import parse_data_type
211+
>>> import numpy as np
212+
>>> parse_data_type("int32", zarr_format=2)
213+
Int32(endianness='little')
214+
>>> parse_data_type(np.dtype('S10'), zarr_format=2)
215+
NullTerminatedBytes(length=10)
216+
>>> parse_data_type({"name": "numpy.datetime64", "configuration": {"unit": "s", "scale_factor": 10}}, zarr_format=3)
217+
DateTime64(endianness='little', scale_factor=10, unit='s')
192218
"""
193219
if isinstance(dtype_spec, ZDType):
194220
return dtype_spec

0 commit comments

Comments
 (0)