[Numpy-discussion] datetime64 1970 issue

Ondřej Čertík ondrej.certik at gmail.com
Tue Apr 16 19:45:16 EDT 2013


On Tue, Apr 16, 2013 at 4:55 PM, Bob Nnamtrop <bob.nnamtrop at gmail.com> wrote:
> I am curious if others have noticed an issue with datetime64 at the
> beginning of 1970. First:
>
> In [144]: (np.datetime64('1970-01-01') - np.datetime64('1969-12-31'))
> Out[144]: numpy.timedelta64(1,'D')
>
> OK this look fine, they are one day apart. But look at this:
>
> In [145]: (np.datetime64('1970-01-01 00') - np.datetime64('1969-12-31 00'))
> Out[145]: numpy.timedelta64(31,'h')
>
> Hmmm, seems like there are 7 extra hours? Am I missing something? I don't
> see this at any other year. This discontinuity makes it hard to use the
> datetime64 object without special adjustment in ones code. I assume this a
> bug?

Indeed, this looks like a bug, I can reproduce it on linux as well:

In [1]: import numpy as np

In [2]: np.datetime64('1970-01-01') - np.datetime64('1969-12-31')
Out[2]: numpy.timedelta64(1,'D')

In [3]: np.datetime64('1970-01-01 00') - np.datetime64('1969-12-31 00')
Out[3]: numpy.timedelta64(31,'h')

In [4]: np.__version__
Out[4]: '1.7.1'


We need to look into the sources to see what is going on.

Ondrej



More information about the NumPy-Discussion mailing list