Skip to content

Commit b161fa7

Browse files
authored
REF: Resampler subclasses remove unused arg, ensure parent is not None (#51163)
1 parent ca9878e commit b161fa7

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

pandas/core/resample.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
Callable,
88
Hashable,
99
Literal,
10+
cast,
1011
final,
1112
no_type_check,
1213
)
@@ -466,7 +467,7 @@ def _get_resampler_for_grouping(self, groupby, key=None):
466467
"""
467468
Return the correct class for resampling with groupby.
468469
"""
469-
return self._resampler_for_grouping(self, groupby=groupby, key=key)
470+
return self._resampler_for_grouping(groupby=groupby, key=key, parent=self)
470471

471472
def _wrap_result(self, result):
472473
"""
@@ -1142,11 +1143,11 @@ class _GroupByMixin(PandasObject):
11421143
_attributes: list[str] # in practice the same as Resampler._attributes
11431144
_selection: IndexLabel | None = None
11441145

1145-
def __init__(self, obj, parent=None, groupby=None, key=None, **kwargs) -> None:
1146+
def __init__(self, *, parent: Resampler, groupby=None, key=None, **kwargs) -> None:
11461147
# reached via ._gotitem and _get_resampler_for_grouping
11471148

1148-
if parent is None:
1149-
parent = obj
1149+
# parent is always a Resampler, sometimes a _GroupByMixin
1150+
assert isinstance(parent, Resampler), type(parent)
11501151

11511152
# initialize our GroupByMixin object with
11521153
# the resampler attributes
@@ -1219,7 +1220,10 @@ def _gotitem(self, key, ndim, subset=None):
12191220
selection = key
12201221

12211222
new_rs = type(self)(
1222-
subset, groupby=groupby, parent=self, selection=selection, **kwargs
1223+
groupby=groupby,
1224+
parent=cast(Resampler, self),
1225+
selection=selection,
1226+
**kwargs,
12231227
)
12241228
return new_rs
12251229

0 commit comments

Comments
 (0)