From f3cf0561179f029981a9f74744254f872923fb7f Mon Sep 17 00:00:00 2001 From: Brock Date: Fri, 3 Feb 2023 09:54:59 -0800 Subject: [PATCH 1/2] REF: remove _GroupByMixin._shallow_copy --- pandas/core/resample.py | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/pandas/core/resample.py b/pandas/core/resample.py index d3b3c844e8c4e..007d70c252159 100644 --- a/pandas/core/resample.py +++ b/pandas/core/resample.py @@ -170,18 +170,6 @@ def __init__( else: self.exclusions = frozenset() - @final - def _shallow_copy(self, obj, **kwargs): - """ - return a new object with the replacement attributes - """ - if isinstance(obj, self._constructor): - obj = obj.obj - for attr in self._attributes: - if attr not in kwargs: - kwargs[attr] = getattr(self, attr) - return self._constructor(obj, **kwargs) - def __str__(self) -> str: """ Provide a nice str repr of our rolling object. @@ -1178,7 +1166,7 @@ def _apply(self, f, *args, **kwargs): """ def func(x): - x = self._shallow_copy(x, groupby=self.groupby) + x = self._resampler_cls(x, groupby=self.groupby) if isinstance(f, str): return getattr(x, f)(**kwargs) @@ -1361,7 +1349,7 @@ class DatetimeIndexResamplerGroupby(_GroupByMixin, DatetimeIndexResampler): """ @property - def _constructor(self): + def _resampler_cls(self): return DatetimeIndexResampler @@ -1473,7 +1461,7 @@ class PeriodIndexResamplerGroupby(_GroupByMixin, PeriodIndexResampler): """ @property - def _constructor(self): + def _resampler_cls(self): return PeriodIndexResampler @@ -1501,7 +1489,7 @@ class TimedeltaIndexResamplerGroupby(_GroupByMixin, TimedeltaIndexResampler): """ @property - def _constructor(self): + def _resampler_cls(self): return TimedeltaIndexResampler From 5f772d0b8c67b1c572137caaa627d5b503cda58f Mon Sep 17 00:00:00 2001 From: Brock Date: Fri, 3 Feb 2023 10:51:50 -0800 Subject: [PATCH 2/2] dont pass ignored-kwargs to Resampler --- pandas/core/resample.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pandas/core/resample.py b/pandas/core/resample.py index 007d70c252159..18e47b095bea7 100644 --- a/pandas/core/resample.py +++ b/pandas/core/resample.py @@ -150,7 +150,6 @@ def __init__( *, group_keys: bool | lib.NoDefault = lib.no_default, selection=None, - **kwargs, ) -> None: self.groupby = groupby self.keys = None