Thank you for your time.

A colleague asked me about creating a range of numpy datetime64 at 15-day increments.

This works:
np.arange(np.datetime64('2008-04-01'), np.datetime64('2020-09-01'), np.timedelta64(15, 'D'))
but then they also showed me this, which leads to some very strange responses:

np.arange(np.datetime64('2008-04-01'), np.datetime64('2020-09-01'), dtype="datetime64[15D]")
array(['2008-03-27', '2008-04-11', '2008-04-26', '2008-05-11',
       '2008-05-26', '2008-06-10', '2008-06-25', '2008-07-10',
       '2020-05-23', '2020-06-07', '2020-06-22', '2020-07-07',
       '2020-07-22', '2020-08-06'], dtype='datetime64[15D]')

See how the 1st day is March 27th?

I couldn't find a reference to this dtype ( "datetime64[15D]" ) in the numpy docs, but I think it's a common pattern in Pandas, that is using a number to get an increment of the frequency, for example "5T" is 5-minutes, etc.

There is a reference to using arange with dtype on the datetimes & timedelta doc page () but the datetime is 1-day or  "datetime64[D]"

Is this the intended outcome? Or is it a side effect?

I wonder if others have tried to adapt Pandas patterns to Numpy datetimes, and if it's an issue for anyone else.

I've advised my colleague not to use Numpy datetimes like this, assuming based on the docs that Pandas-style offsets do not translate into Numpy style datetimes.


Mark Mikofski, PhD (2005)
Fiat Lux