-
-
Notifications
You must be signed in to change notification settings - Fork 18.6k
ENH: add end and end_day origin for resample #38408
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
Changes from all commits
5e8f034
8dce4e3
f316aea
20e15e4
11e1252
edfe52a
f47b6ea
0cc22cd
e6ae1a5
a2e0a57
8fcc8f0
2ffce3c
a554cad
546d647
ab473ce
8331a8e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -82,7 +82,8 @@ class Grouper: | |
However, loffset is also deprecated for ``.resample(...)`` | ||
See: :class:`DataFrame.resample` | ||
|
||
origin : {'epoch', 'start', 'start_day'}, Timestamp or str, default 'start_day' | ||
origin : {{'epoch', 'start', 'start_day', 'end', 'end_day'}}, Timestamp | ||
or str, default 'start_day' | ||
The timestamp on which to adjust the grouping. The timezone of origin must | ||
match the timezone of the index. | ||
If a timestamp is not used, these values are also supported: | ||
|
@@ -93,6 +94,11 @@ class Grouper: | |
|
||
.. versionadded:: 1.1.0 | ||
|
||
- 'end': `origin` is the last value of the timeseries | ||
- 'end_day': `origin` is the ceiling midnight of the last day | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comment/question here. |
||
|
||
.. versionadded:: 1.3.0 | ||
|
||
offset : Timedelta or str, default is None | ||
An offset timedelta added to the origin. | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -611,3 +611,80 @@ def test_resample_agg_readonly(): | |
|
||
result = rs.agg("min") | ||
tm.assert_series_equal(result, expected) | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is it possible to parametrize these tests? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
|
||
@pytest.mark.parametrize( | ||
"start,end,freq,data,resample_freq,origin,closed,exp_data,exp_end,exp_periods", | ||
[ | ||
( | ||
"2000-10-01 23:30:00", | ||
"2000-10-02 00:26:00", | ||
"7min", | ||
[0, 3, 6, 9, 12, 15, 18, 21, 24], | ||
"17min", | ||
"end", | ||
None, | ||
[0, 18, 27, 63], | ||
"20001002 00:26:00", | ||
4, | ||
), | ||
( | ||
"20200101 8:26:35", | ||
"20200101 9:31:58", | ||
"77s", | ||
[1] * 51, | ||
"7min", | ||
"end", | ||
"right", | ||
[1, 6, 5, 6, 5, 6, 5, 6, 5, 6], | ||
"2020-01-01 09:30:45", | ||
10, | ||
), | ||
( | ||
"2000-10-01 23:30:00", | ||
"2000-10-02 00:26:00", | ||
"7min", | ||
[0, 3, 6, 9, 12, 15, 18, 21, 24], | ||
"17min", | ||
"end", | ||
"left", | ||
[0, 18, 27, 39, 24], | ||
"20001002 00:43:00", | ||
5, | ||
), | ||
( | ||
"2000-10-01 23:30:00", | ||
"2000-10-02 00:26:00", | ||
"7min", | ||
[0, 3, 6, 9, 12, 15, 18, 21, 24], | ||
"17min", | ||
"end_day", | ||
None, | ||
[3, 15, 45, 45], | ||
"2000-10-02 00:29:00", | ||
4, | ||
), | ||
], | ||
) | ||
def test_end_and_end_day_origin( | ||
start, | ||
end, | ||
freq, | ||
data, | ||
resample_freq, | ||
origin, | ||
closed, | ||
exp_data, | ||
exp_end, | ||
exp_periods, | ||
): | ||
rng = date_range(start, end, freq=freq) | ||
ts = Series(data, index=rng) | ||
|
||
res = ts.resample(resample_freq, origin=origin, closed=closed).sum() | ||
expected = Series( | ||
exp_data, | ||
index=date_range(end=exp_end, freq=resample_freq, periods=exp_periods), | ||
) | ||
|
||
tm.assert_series_equal(res, expected) |
Uh oh!
There was an error while loading. Please reload this page.