Skip to content

Commit 31d3c6d

Browse files
committed
modify tutorial for datetime support
1 parent 4c5e164 commit 31d3c6d

File tree

1 file changed

+4
-15
lines changed

1 file changed

+4
-15
lines changed

docs/tutorial.rst

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1079,24 +1079,13 @@ E.g., pickle/unpickle an array stored on disk::
10791079
Datetimes and timedeltas
10801080
------------------------
10811081

1082-
Please note that NumPy's ``datetime64`` and ``timedelta64`` dtypes are **not** currently
1083-
supported for Zarr arrays. If you would like to store datetime or timedelta data, you
1084-
can store the data in an array with an integer dtype, e.g.::
1082+
NumPy's ``datetime64`` ('M') and ``timedelta64`` ('m') dtypes are supported for Zarr
1083+
arrays, as long as the units are specified. E.g.::
10851084

1086-
>>> a = np.array(['2007-07-13', '2006-01-13', '2010-08-13'], dtype='datetime64[D]')
1087-
>>> z = zarr.array(a.view('i8'))
1085+
>>> z = zarr.array(['2007-07-13', '2006-01-13', '2010-08-13'], dtype='M[D]')
10881086
>>> z
1089-
<zarr.core.Array (3,) int64>
1087+
<zarr.core.Array (3,) datetime64[D]>
10901088
>>> z[:]
1091-
array([13707, 13161, 14834])
1092-
>>> z[:].view(a.dtype)
1093-
array(['2007-07-13', '2006-01-13', '2010-08-13'], dtype='datetime64[D]')
1094-
1095-
If you would like a convenient way to retrieve the data from this array viewed as the
1096-
original datetime64 dtype, try the :func:`zarr.core.Array.astype` method, e.g.::
1097-
1098-
>>> zv = z.astype(a.dtype)
1099-
>>> zv[:]
11001089
array(['2007-07-13', '2006-01-13', '2010-08-13'], dtype='datetime64[D]')
11011090

11021091
.. _tutorial_tips:

0 commit comments

Comments
 (0)