[Numpy-discussion] Default unit for datetime/timedelta

Mark Wiebe mwwiebe@gmail....
Wed Jun 8 16:05:29 CDT 2011

The NEP and current implementation of the datetime specifies microseconds as
the default unit when constructing and converting to datetimes and
timedeltas. Having the np.arange function work in a general, intuitive way
for a wide variety of datetime/timedelta/integer inputs is turning out to be
very complicated, and has made me realized that adding a "generic time unit"
which gets assigned to the data type when unspecified would simplify this
code and also make it more consistent with the behavior of +/- operations.

Here are some current behaviors that are inconsistent with the microsecond
default, but consistent with the "generic time unit" idea:

>>> np.timedelta64(10, 's') + 10

>>> np.datetime64('2011-03-12') + 3

I'd like to make 'M8' and 'm8' be datetime data types with generic time
units instead of microseconds as they are currently. This would also allow
the possibility of extending the behavior of detecting the unit from the
input string as:

>>> np.datetime64('2011-03-12T13')

to also work with arrays, which currently work like this:

>>> np.array(['2011-03-12T13', '2012'], dtype='M8')
'2011-12-31T18:00:00.000000-0600'], dtype='datetime64[us]')

This is similar to some cases of the string data type, where the size of the
string is detected based on the input.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20110608/7892333e/attachment-0001.html 

More information about the NumPy-Discussion mailing list