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
_______________________________________________
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion

Reply via email to