-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: groupby with resample using on parameter errors when selecting column to apply function #19433
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
e4ca463
to
836139e
Compare
Codecov Report
@@ Coverage Diff @@
## master #19433 +/- ##
==========================================
- Coverage 91.62% 91.59% -0.03%
==========================================
Files 150 150
Lines 48714 48720 +6
==========================================
- Hits 44633 44625 -8
- Misses 4081 4095 +14
Continue to review full report at Codecov.
|
try with something like this. your patch is just working around the issue and not fixing it at the source. its pretty deep code, but try here.
|
I applied your diff. The result, in this case, would be:
instead of:
But I got your idea. The main challenge is that |
838c058
to
b4dbb59
Compare
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.
change looks good. some comments. ping on green.
doc/source/whatsnew/v0.23.0.txt
Outdated
@@ -548,7 +548,7 @@ Groupby/Resample/Rolling | |||
- Bug in :func:`DataFrame.resample` which silently ignored unsupported (or mistyped) options for ``label``, ``closed`` and ``convention`` (:issue:`19303`) | |||
- Bug in :func:`DataFrame.groupby` where tuples were interpreted as lists of keys rather than as keys (:issue:`17979`, :issue:`18249`) | |||
- Bug in ``transform`` where particular aggregation functions were being incorrectly cast to match the dtype(s) of the grouped data (:issue:`19200`) | |||
- | |||
- Bug in `DataFrame.groupby` with resample using `on` parameter when selecting column to apply function (:issue:`17813`) |
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.
passing the on=
kwarg, and subsequently using .apply()
(not the double backticks on both)
pandas/core/groupby.py
Outdated
if key not in obj._info_axis: | ||
raise KeyError("The grouper name {0} is not found".format(key)) | ||
ax = Index(obj[key], name=key) | ||
if getattr(self.grouper, 'name', None) == key and \ |
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.
can you add a comment here about what this is doing (IOW the on is already defined).
use ABCSeries
rather than Series
pandas/tests/test_resample.py
Outdated
@@ -252,6 +252,15 @@ def test_pipe(self): | |||
result = r.pipe(lambda x: x.max() - x.mean()) | |||
tm.assert_frame_equal(result, expected) | |||
|
|||
def test_groupby_resample_on_api_with_getitem(self): |
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.
can you move this a bit lower down in the file (immediately after the other getitem tests)
thanks @discort |
…olumn to apply function closes pandas-dev#17813 Author: discort <[email protected]> Closes pandas-dev#19433 from discort/fix_17813 and squashes the following commits: 2f25d40 [discort] Fixed bug in df.resample using 'on' parameter
git diff upstream/master -u -- "*.py" | flake8 --diff