Skip to content

Adding Timedelta parameter to time-based .rolling() #15440

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
chrisaycock opened this issue Feb 17, 2017 · 6 comments · Fixed by #15443
Closed

Adding Timedelta parameter to time-based .rolling() #15440

chrisaycock opened this issue Feb 17, 2017 · 6 comments · Fixed by #15443
Labels
Bug Frequency DateOffsets Reshaping Concat, Merge/Join, Stack/Unstack, Explode
Milestone

Comments

@chrisaycock
Copy link
Contributor

chrisaycock commented Feb 17, 2017

Starting with a simple DataFrame:

n = 10
df = pd.DataFrame({'value': np.arange(n)},
                  index=pd.date_range('2015-12-24', periods=n, freq="D"))

I can invoke a time-based .rolling() with a string for the offset:

df.rolling('3d').sum()

I would like to invoke it with a Timedelta since it is easier to arithmetically change the window length:

df.rolling(pd.Timedelta(days=3)).sum()
@chrisaycock chrisaycock changed the title Adding Timedelta parameter to time-based rolling Adding Timedelta parameter to time-based .rolling() Feb 17, 2017
@jreback
Copy link
Contributor

jreback commented Feb 17, 2017

hmm, it allows offsets already (in fact internally that's all its doing), so this must be just an oversight

In [7]: df.rolling(pd.tseries.frequencies.to_offset(pd.Timedelta(days=3))).sum()
Out[7]: 
            value
2015-12-24    0.0
2015-12-25    1.0
2015-12-26    3.0
2015-12-27    6.0
2015-12-28    9.0
2015-12-29   12.0
2015-12-30   15.0
2015-12-31   18.0
2016-01-01   21.0
2016-01-02   24.0

@jreback jreback added Bug Difficulty Novice Frequency DateOffsets Reshaping Concat, Merge/Join, Stack/Unstack, Explode labels Feb 17, 2017
@jreback jreback added this to the 0.20.0 milestone Feb 17, 2017
@chrisaycock
Copy link
Contributor Author

Ah, I hadn't known about to_offset()! That's neat.

@fjanoos
Copy link

fjanoos commented Feb 17, 2017

Thanks ! it would be great though if Timedelta were directly supported !

@jreback
Copy link
Contributor

jreback commented Feb 17, 2017

@fjanoos we already use to_offset internally

In [1]: from pandas.tseries.frequencies import to_offset

In [2]: to_offset(pd.offsets.Day(1)).nanos
Out[2]: 86400000000000

In [4]: to_offset(pd.Timedelta('1 day')).nanos
Out[4]: 86400000000000

this is just a matter of fixing the checking.

pull-requests are welcomed!

@fjanoos
Copy link

fjanoos commented Mar 5, 2017

Is this change in the master branch now ?

@jreback
Copy link
Contributor

jreback commented Mar 5, 2017

yep closed via #15443

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Frequency DateOffsets Reshaping Concat, Merge/Join, Stack/Unstack, Explode
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants