[Numpy-discussion] The date/time dtype and the casting issue

Francesc Alted faltet@pytables....
Tue Jul 29 11:17:01 CDT 2008


Ops, after reviewing this document, I've discovered a couple of typos.

A Tuesday 29 July 2008, Francesc Alted escrigué:
[snip]
> >>> series = numpy.array(['1970-01-01', '1970-02-01', '1970-09-01'], 
> dtype='datetime64[D]')
> >>> series2 = series + numpy.timedelta(1, 'Y')  # Add 2 years
                                        ^^^
the above line should read:

>>> series2 = series + numpy.timedelta(2, 'Y')  # Add 2 years

> >>> series2
>
> array(['1972-01-01', '1972-02-01', '1972-09-01'],
> dtype='datetime64[D]')  # the 'D'ay time unit has been chosen

[snip]

> >>> numpy.change_unit( numpy.array([1,2], 'T[Y]'), 'T[d]' )
>
> array([365, 731], dtype="datetime64[d]")
>
> or:
> >>> ref = numpy.datetime64('1971', 'T[Y]')
> >>> numpy.change_unit( numpy.array([1,2], 't[Y]'), 't[d]',  ref )
>
> array([366, 365], dtype="timedelta64[d]")
              ^^^
the above line should read:

array([366, 731], dtype="timedelta64[d]")


-- 
Francesc Alted


More information about the Numpy-discussion mailing list