[Numpy-discussion] datetime64 1970 issue

Chris Barker - NOAA Federal chris.barker@noaa....
Wed Apr 17 11:04:08 CDT 2013


On Tue, Apr 16, 2013 at 8:23 PM, Zachary Ploskey <zploskey@gmail.com> wrote:
> The problem does not appear to exist on Linux with numpy version 1.6.2.

datetime64 was re-vampded a fair bit between 1.6 and 1.7

something is up here for sure with 1.7

We can be more dramatic about it:

In [5]: np.datetime64('1970-01-01T00') - np.datetime64('1969-12-31T23:59 ')
Out[5]: numpy.timedelta64(481,'m')

In [6]: np.datetime64('1970-01-01T00:00') - np.datetime64('1969-12-31T23:59 ')
Out[6]: numpy.timedelta64(481,'m')

1970-01-01T00 is the epoch, of course, so no surprise that if there is
something wrong, it would be there.

Interesting that no one noticed this before -- I guess I haven't
happened to use pre-1970 dates -- and or didn't check for accuracy
down to a few hours...

I'd say we need some more unit-tests!

We've been discussion some changes to datetime64 anyway, so a good
time to open it up.

-CHris


> In [1]: import numpy as np
>
> In [2]: np.datetime64('1970-01-01') - np.datetime64('1969-12-31')
> Out[2]: 1 day, 0:00:00
>
> In [3]: np.datetime64('1970-01-01 00') - np.datetime64('1969-12-31 00')
> Out[3]: 1 day, 0:00:00
>
> In [4]: np.__version__
> Out[4]: '1.6.2'
>
> Zach
>
>
> On Tue, Apr 16, 2013 at 4:45 PM, Ondřej Čertík <ondrej.certik@gmail.com>
> wrote:
>>
>> On Tue, Apr 16, 2013 at 4:55 PM, Bob Nnamtrop <bob.nnamtrop@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
>> _______________________________________________
>> NumPy-Discussion mailing list
>> NumPy-Discussion@scipy.org
>> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>
>
>
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion@scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>



-- 

Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

Chris.Barker@noaa.gov


More information about the NumPy-Discussion mailing list