[Numpy-discussion] code review for datetime arange

Mark Wiebe mwwiebe@gmail....
Thu Jun 9 15:01:17 CDT 2011


I've replaced the previous two pull requests with a single pull request
rolling up all the changes so far. The newest changes include finishing the
generic unit and np.arange function support.

https://github.com/numpy/numpy/pull/87

Because of the nature of datetime and timedelta, arange has to be slightly
different than with all the other types. In particular, for datetime the
primary signature is np.arange(datetime, datetime, timedelta).

I've implemented a simple extension which allows for another way to specify
a date range, as np.arange(datetime, timedelta, timedelta). Here (start,
delta) represents the datetime range [start, start+delta). Some examples:

>>> np.arange('2011', '2020', dtype='M8[Y]')
array(['2011', '2012', '2013', '2014', '2015', '2016', '2017', '2018',
       '2019'], dtype='datetime64[Y]')

>>> np.arange('today', 10, 3, dtype='M8')
array(['2011-06-09', '2011-06-12', '2011-06-15', '2011-06-18'],
dtype='datetime64[D]')

>>> a = np.datetime64('today', 'M')
>>> np.arange(a, a+1, dtype='M8[D]')
array(['2011-06-01', '2011-06-02', '2011-06-03', '2011-06-04',
       '2011-06-05', '2011-06-06', '2011-06-07', '2011-06-08',
       '2011-06-09', '2011-06-10', '2011-06-11', '2011-06-12',
       '2011-06-13', '2011-06-14', '2011-06-15', '2011-06-16',
       '2011-06-17', '2011-06-18', '2011-06-19', '2011-06-20',
       '2011-06-21', '2011-06-22', '2011-06-23', '2011-06-24',
       '2011-06-25', '2011-06-26', '2011-06-27', '2011-06-28',
       '2011-06-29', '2011-06-30'], dtype='datetime64[D]')

Please build the branch available here,

https://github.com/m-paradox/numpy

try it out, and then discuss!

-Mark
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20110609/30df3148/attachment.html 


More information about the NumPy-Discussion mailing list