Skip to content

date_range should take timedelta as freq #6307

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
hayd opened this issue Feb 8, 2014 · 7 comments
Closed

date_range should take timedelta as freq #6307

hayd opened this issue Feb 8, 2014 · 7 comments
Assignees
Labels
Enhancement Frequency DateOffsets Timedelta Timedelta data type

Comments

@hayd
Copy link
Contributor

hayd commented Feb 8, 2014

@hayd hayd self-assigned this Feb 8, 2014
@c0indev3l
Copy link

I think passing a timedelta as freq can only make sense for timeframe below 1 month but it would still be very useful. Maybe an idea could be to provide a way to build a DateOffset from a timedelta

@hayd
Copy link
Contributor Author

hayd commented Feb 10, 2014

Agree, re making an offset. A from_timedelta method would make sense.

@jreback
Copy link
Contributor

jreback commented Feb 10, 2014

I think u could directly interpret a time delta as a passed freq
like to do a PR

@hayd
Copy link
Contributor Author

hayd commented Feb 10, 2014

I changed the pd.tseries.frequencies.to_offset to accept timedeltas in the PR.

It lazily forces it to Nano/Micro, could be more clever...

@jreback
Copy link
Contributor

jreback commented Feb 10, 2014

hmm these should try to upcast these (eg return seconds, minutes, days etc if possible
eg maybe extracts days, seconds , microseconds from timedeltas and then convert as appropriate ( their might be some methods in tseries.timedeltas to help with this - don't remember )

@jreback jreback modified the milestones: 0.15.0, 0.14.0 Apr 27, 2014
@jreback jreback modified the milestones: 0.14.1, 0.15.0 May 28, 2014
@jreback jreback modified the milestones: 0.15.0, 0.14.1 Jun 22, 2014
@jreback jreback modified the milestones: 0.15.0, 0.15.1 Jul 6, 2014
@jreback jreback modified the milestones: 0.15.1, 0.15.0 Sep 4, 2014
@jreback jreback modified the milestones: 0.16.0, Next Major Release Mar 6, 2015
@jbrockmendel
Copy link
Member

This works in 0.21.1

>>> td = pd.Timedelta(days=3, hours=4)
pd.date_range('2016-01-01', periods=4, freq=td)
DatetimeIndex(['2016-01-01 00:00:00', '2016-01-04 04:00:00',
               '2016-01-07 08:00:00', '2016-01-10 12:00:00'],
              dtype='datetime64[ns]', freq='76H')

This can probably be closed.

@jreback
Copy link
Contributor

jreback commented Dec 19, 2017

yes this is well tested

@jschendel did a PR. awhile back on this iirc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement Frequency DateOffsets Timedelta Timedelta data type
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants