Skip to content

REF: always use grouper=self.grouper in resample #43484

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

Merged
merged 1 commit into from
Sep 10, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions pandas/core/resample.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,8 +338,7 @@ def aggregate(self, func=None, *args, **kwargs):
result = ResamplerWindowApply(self, func, args=args, kwargs=kwargs).agg()
if result is None:
how = func
grouper = None
result = self._groupby_and_aggregate(how, grouper, *args, **kwargs)
result = self._groupby_and_aggregate(how, *args, **kwargs)

result = self._apply_loffset(result)
return result
Expand Down Expand Up @@ -409,12 +408,11 @@ def _gotitem(self, key, ndim: int, subset=None):
except KeyError:
return grouped

def _groupby_and_aggregate(self, how, grouper=None, *args, **kwargs):
def _groupby_and_aggregate(self, how, *args, **kwargs):
"""
Re-evaluate the obj with a groupby aggregation.
"""
if grouper is None:
grouper = self.grouper
grouper = self.grouper

obj = self._selected_obj

Expand Down Expand Up @@ -1055,7 +1053,7 @@ def __init__(self, obj, parent=None, groupby=None, **kwargs):
self.groupby = copy.copy(parent.groupby)

@no_type_check
def _apply(self, f, grouper=None, *args, **kwargs):
def _apply(self, f, *args, **kwargs):
"""
Dispatch to _upsample; we are stripping all of the _upsample kwargs and
performing the original function call on the grouped object.
Expand Down Expand Up @@ -1296,15 +1294,15 @@ def _downsample(self, how, **kwargs):

if is_subperiod(ax.freq, self.freq):
# Downsampling
return self._groupby_and_aggregate(how, grouper=self.grouper, **kwargs)
return self._groupby_and_aggregate(how, **kwargs)
elif is_superperiod(ax.freq, self.freq):
if how == "ohlc":
# GH #13083
# upsampling to subperiods is handled as an asfreq, which works
# for pure aggregating/reducing methods
# OHLC reduces along the time dimension, but creates multiple
# values for each period -> handle by _groupby_and_aggregate()
return self._groupby_and_aggregate(how, grouper=self.grouper)
return self._groupby_and_aggregate(how)
return self.asfreq()
elif ax.freq == self.freq:
return self.asfreq()
Expand Down