0

Is there a reason why conversion from datetime.datetime array, without specifying units us, converts the datetime to full day? Or is this a bug?

import numpy as np
import datetime
print(np.array([datetime.datetime(2018, 5, 15, 6, 0),datetime.datetime(2018, 5, 15, 6, 30)]).astype('datetime64[us]'))
print(np.array([datetime.datetime(2018, 5, 15, 6, 0),datetime.datetime(2018, 5, 15, 6, 30)]).astype('datetime64'))

output

['2018-05-15T06:00:00.000000' '2018-05-15T06:30:00.000000']
['2018-05-15' '2018-05-15']

numpy version 1.14.3 and python 3.6.3

From the numpy documentation, I cannot see that default unit of datetime64 is day. from https://docs.scipy.org/doc/numpy-1.14.0/reference/arrays.datetime.html

>>> np.array(['2001-01-01T12:00', '2002-02-03T13:56:03.172'], dtype='datetime64')
array(['2001-01-01T12:00:00.000-0600', '2002-02-03T13:56:03.172-0600'], dtype='datetime64[ms]')
kakk11
  • 898
  • 8
  • 21
  • I don't know if this is a bug or not, the docs aren't clear as they don't show what the behaviour is when passing `datetime.datetime` so there it looks like the coercion is not behaving as expected – EdChum May 16 '18 at 10:51
  • Thanks @EdChum , I guess I'll open numpy issue, as the behavior is unintuitive at best. – kakk11 May 16 '18 at 11:05

0 Answers0