[Numpy-discussion] Changing the datetime operation unit rules
Mark Wiebe
mwwiebe@gmail....
Tue Jun 7 15:55:19 CDT 2011
The NEP for datetime specifies a set of rules for how units should behave
when combined with + or -. After playing around with the implementation a
bit, I think the rules need to be changed. First, subtracting two
datetime64's should produce the more precise unit. This allows things like
the following, to recover the current day offset in the current year:
>>> a = np.datetime64('today')
>>> a - a.astype('M8[Y]')
numpy.timedelta64(157,'D')
vs
>>> a = np.datetime64('today')
>>> a - a.astype('M8[Y]')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: ufunc subtract cannot use operands with types
dtype('datetime64[D]') and dtype('datetime64[Y]')
Similarly, a datetime64 +/- timedelta64 should also produce the more precise
unit, because things like the following intuitively should produce a date,
not truncate back to the year:
>>> np.datetime64('2011') + np.timedelta64(3,'M') + np.timedelta64(5,'D')
numpy.datetime64('2011-04-06','D')
vs
>>> np.datetime64('2011') + np.timedelta64(3,'M') + np.timedelta64(5,'D')
numpy.datetime64('2011','Y')
Cheers,
Mark
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20110607/4f118220/attachment.html
More information about the NumPy-Discussion
mailing list