-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
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
Conversation
I have revert the backward arg and only add the end and end_day. |
doc/source/whatsnew/v1.2.0.rst
Outdated
@@ -292,6 +292,7 @@ Other enhancements | |||
- Improved error reporting for subsetting columns of a :class:`.DataFrameGroupBy` with ``axis=1`` (:issue:`37725`) | |||
- Implement method ``cross`` for :meth:`DataFrame.merge` and :meth:`DataFrame.join` (:issue:`5401`) | |||
- When :func:`read_csv/sas/json` are called with ``chuncksize``/``iterator`` they can be used in a ``with`` statement as they return context-managers (:issue:`38225`) | |||
- Added ``end`` and ``end_day`` options for ``origin`` in :meth:`DataFrame.resample` (:issue:`37804`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure this will make it in for 1.2 - might need to move to 1.3
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jreback keep this in 1.2 or remove to 1.3 whatsnew?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed that this should target 1.3
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
@@ -611,3 +611,76 @@ 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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
done
ts = Series(np.arange(len(rng)) * 3, index=rng) | ||
|
||
res = ts.resample("17min", origin="end").sum().astype("int64") | ||
data = [0, 18, 27, 63] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i'd stick that in the constructor
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mroeschke said constructing ts
in each test was better.
pandas/core/resample.py
Outdated
self.origin = origin | ||
else: | ||
try: | ||
self.origin = Timestamp(origin) | ||
except Exception as e: | ||
raise ValueError( | ||
"'origin' should be equal to 'epoch', 'start', 'start_day' or " | ||
"'origin' should be equal to 'epoch', 'start', 'start_day', " | ||
"'end' or 'end_day' " |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"'end', 'end_day', or "
@@ -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 comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment/question here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two comments otherwise LGTM
Do u think it's worthwhile to explain more about these two backward resample method in ENH of whatsnew (maybe two examples added)? |
Probably good to add to |
ok |
failures unrelated |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
small comment, pls merge master and ping on green.
cc @mroeschke if any other comments
pandas/core/generic.py
Outdated
@@ -8027,7 +8027,8 @@ def resample( | |||
level : str or int, optional | |||
For a MultiIndex, level (name or number) to use for | |||
resampling. `level` must be datetime-like. | |||
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' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think you have to indent this 2nd line
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here has a line-continuation at the end of 1st line, will this break the display if I indent the 'or str, default "start_day"' with 4 spaces?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah saw that but we don't usually use continuation like that
it will render if you indent on 2nd line
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
Now I change it to the following format.
Will this be wrongly rendered to this? origin : {{'epoch', 'start', 'start_day', 'end', 'end_day'}}, Timestamp Instead of: origin : {{'epoch', 'start', 'start_day', 'end', 'end_day'}}, Timestamp or str, default 'start_day' |
thanks @GYHHAHA |
black pandas
git diff upstream/master -u -- "*.py" | flake8 --diff