[Numpy-discussion] datetime64 constructor ignores dtype argument?

Dave Hirschfeld dave.hirschfeld at gmail.com
Wed Jun 12 06:07:30 EDT 2013


The example below demonstrates the fact that the datetime64 constructor 
ignores the dtype argument if passed in. Is this conscious design decision or 
a bug/oversight?


In [55]: from datetime import datetime
    ...: d = datetime.now()
    ...: 

In [56]: d
Out[56]: datetime.datetime(2013, 6, 12, 11, 3, 27, 861000)

In [57]: np.datetime64(d)
Out[57]: numpy.datetime64('2013-06-12T12:03:27.861000+0100')

In [58]: np.datetime64(d).dtype
Out[58]: dtype('<M8[us]')

In [59]: np.datetime64(d, dtype='M8[D]')
Out[59]: numpy.datetime64('2013-06-12T12:03:27.861000+0100')

In [60]: np.datetime64(d, dtype='M8[D]').dtype
Out[60]: dtype('<M8[us]')   <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< ???

In [61]: np.datetime64(d).astype('M8[D]')
Out[61]: numpy.datetime64('2013-06-12')


Thanks,
Dave




More information about the NumPy-Discussion mailing list