Skip to content

Commit e385d27

Browse files
committed
finish up datetime support
1 parent 31d3c6d commit e385d27

File tree

4 files changed

+6
-4
lines changed

4 files changed

+6
-4
lines changed

docs/tutorial.rst

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

1082-
NumPy's ``datetime64`` ('M') and ``timedelta64`` ('m') dtypes are supported for Zarr
1082+
NumPy's ``datetime64`` ('M8') and ``timedelta64`` ('m8') dtypes are supported for Zarr
10831083
arrays, as long as the units are specified. E.g.::
10841084

1085-
>>> z = zarr.array(['2007-07-13', '2006-01-13', '2010-08-13'], dtype='M[D]')
1085+
>>> z = zarr.array(['2007-07-13', '2006-01-13', '2010-08-13'], dtype='M8[D]')
10861086
>>> z
10871087
<zarr.core.Array (3,) datetime64[D]>
10881088
>>> z[:]

zarr/meta.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,5 +178,7 @@ def encode_fill_value(v, dtype):
178178
return v
179179
elif dtype.kind == 'U':
180180
return v
181+
elif dtype.kind in 'mM':
182+
return int(v.view('u8'))
181183
else:
182184
return v

zarr/tests/test_core.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -874,7 +874,7 @@ def test_dtypes(self):
874874
for base_type in 'Mm':
875875
for resolution in 'D', 'us', 'ns':
876876
dtype = '{}8[{}]'.format(base_type, resolution)
877-
z = self.create_array(shape=100, dtype=dtype)
877+
z = self.create_array(shape=100, dtype=dtype, fill_value=0)
878878
assert z.dtype == np.dtype(dtype)
879879
a = np.random.randint(0, np.iinfo('u8').max, size=z.shape[0],
880880
dtype='u8').view(dtype)

zarr/util.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ def normalize_dtype(dtype, object_codec):
145145
args = ()
146146
try:
147147
object_codec = codec_registry[codec_id](*args)
148-
except KeyError:
148+
except KeyError: # pragma: no cover
149149
raise ValueError('codec %r for object type %r is not '
150150
'available; please provide an '
151151
'object_codec manually' % (codec_id, key))

0 commit comments

Comments
 (0)