Hi, Thank you for your time. A colleague asked me about creating a range of numpy datetime64 at 15day increments. This works: np.arange(np.datetime64('20080401'), np.datetime64('20200901'), np.timedelta64(15, 'D')) but then they also showed me this, which leads to some very strange responses: np.arange(np.datetime64('20080401'), np.datetime64('20200901'), dtype="datetime64[15D]") Out[50]: array(['20080327', '20080411', '20080426', '20080511', '20080526', '20080610', '20080625', '20080710', ... '20200523', '20200607', '20200622', '20200707', '20200722', '20200806'], 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 5minutes, etc. There is a reference to using arange with dtype on the datetimes & timedelta doc page () but the datetime is 1day 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 Pandasstyle offsets do not translate into Numpy style datetimes. thanks!  Mark Mikofski, PhD (2005) *Fiat Lux*
It's interesting to confirm that people are aware of this syntax! This is intended but perhaps not useful behavior. `datetime64[15D]` is a type that stores dates by the nearest date that is a multiple of 15 days from the unix epoch. Arguably there isn't a situation where using `15D` makes a whole lot of sense, but the generalization is useful  `datetime64[15m]` stores dates rounded to the nearest quarter hour, which is somewhat sensible. Perhaps we should have added support for a custom epoch, which would make your problem go away... On Thu, 10 Sep 2020 at 18:43, Dr. Mark Alexander Mikofski PhD < mikofski@berkeley.edu> wrote:
Hi,
Thank you for your time.
A colleague asked me about creating a range of numpy datetime64 at 15day increments.
This works:
np.arange(np.datetime64('20080401'), np.datetime64('20200901'), np.timedelta64(15, 'D'))
but then they also showed me this, which leads to some very strange responses:
np.arange(np.datetime64('20080401'), np.datetime64('20200901'), dtype="datetime64[15D]") Out[50]: array(['20080327', '20080411', '20080426', '20080511', '20080526', '20080610', '20080625', '20080710', ... '20200523', '20200607', '20200622', '20200707', '20200722', '20200806'], 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 5minutes, etc.
There is a reference to using arange with dtype on the datetimes & timedelta doc page () but the datetime is 1day 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 Pandasstyle offsets do not translate into Numpy style datetimes.
thanks!
 Mark Mikofski, PhD (2005) *Fiat Lux* _______________________________________________ NumPyDiscussion mailing list NumPyDiscussion@python.org https://mail.python.org/mailman/listinfo/numpydiscussion
Hi Eric, Thank you so much for your answer! That explains this interesting behavior:
[np.datetime64('20080401', f'{x}D') for x in range(1, 16)]
[numpy.datetime64('20080401'), numpy.datetime64('20080401','2D'), numpy.datetime64('20080330','3D'), numpy.datetime64('20080330','4D'), numpy.datetime64('20080401','5D'), numpy.datetime64('20080330','6D'), numpy.datetime64('20080327','7D'), numpy.datetime64('20080330','8D'), numpy.datetime64('20080330','9D'), numpy.datetime64('20080401','10D'), numpy.datetime64('20080401','11D'), numpy.datetime64('20080330','12D'), numpy.datetime64('20080324','13D'), numpy.datetime64('20080320','14D'), numpy.datetime64('20080327','15D')] Is there something to be done? Perhaps a change to the documentation? I'm willing to open a PR with your notes from this thread. Thanks! On Thu, Sep 10, 2020 at 11:04 AM Eric Wieser <wieser.eric+numpy@gmail.com> wrote:
It's interesting to confirm that people are aware of this syntax!
This is intended but perhaps not useful behavior.
`datetime64[15D]` is a type that stores dates by the nearest date that is a multiple of 15 days from the unix epoch. Arguably there isn't a situation where using `15D` makes a whole lot of sense, but the generalization is useful  `datetime64[15m]` stores dates rounded to the nearest quarter hour, which is somewhat sensible.
Perhaps we should have added support for a custom epoch, which would make your problem go away...
On Thu, 10 Sep 2020 at 18:43, Dr. Mark Alexander Mikofski PhD < mikofski@berkeley.edu> wrote:
Hi,
Thank you for your time.
A colleague asked me about creating a range of numpy datetime64 at 15day increments.
This works:
np.arange(np.datetime64('20080401'), np.datetime64('20200901'), np.timedelta64(15, 'D'))
but then they also showed me this, which leads to some very strange responses:
np.arange(np.datetime64('20080401'), np.datetime64('20200901'), dtype="datetime64[15D]") Out[50]: array(['20080327', '20080411', '20080426', '20080511', '20080526', '20080610', '20080625', '20080710', ... '20200523', '20200607', '20200622', '20200707', '20200722', '20200806'], 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 5minutes, etc.
There is a reference to using arange with dtype on the datetimes & timedelta doc page () but the datetime is 1day 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 Pandasstyle offsets do not translate into Numpy style datetimes.
thanks!
 Mark Mikofski, PhD (2005) *Fiat Lux* _______________________________________________ NumPyDiscussion mailing list NumPyDiscussion@python.org https://mail.python.org/mailman/listinfo/numpydiscussion
_______________________________________________ NumPyDiscussion mailing list NumPyDiscussion@python.org https://mail.python.org/mailman/listinfo/numpydiscussion
 Mark Mikofski, PhD (2005) *Fiat Lux*
participants (2)

Dr. Mark Alexander Mikofski PhD

Eric Wieser