|
7 | 7 | Callable,
|
8 | 8 | Hashable,
|
9 | 9 | Literal,
|
| 10 | + cast, |
10 | 11 | final,
|
11 | 12 | no_type_check,
|
12 | 13 | )
|
@@ -466,7 +467,7 @@ def _get_resampler_for_grouping(self, groupby, key=None):
|
466 | 467 | """
|
467 | 468 | Return the correct class for resampling with groupby.
|
468 | 469 | """
|
469 |
| - return self._resampler_for_grouping(self, groupby=groupby, key=key) |
| 470 | + return self._resampler_for_grouping(groupby=groupby, key=key, parent=self) |
470 | 471 |
|
471 | 472 | def _wrap_result(self, result):
|
472 | 473 | """
|
@@ -1142,11 +1143,11 @@ class _GroupByMixin(PandasObject):
|
1142 | 1143 | _attributes: list[str] # in practice the same as Resampler._attributes
|
1143 | 1144 | _selection: IndexLabel | None = None
|
1144 | 1145 |
|
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: |
1146 | 1147 | # reached via ._gotitem and _get_resampler_for_grouping
|
1147 | 1148 |
|
1148 |
| - if parent is None: |
1149 |
| - parent = obj |
| 1149 | + # parent is always a Resampler, sometimes a _GroupByMixin |
| 1150 | + assert isinstance(parent, Resampler), type(parent) |
1150 | 1151 |
|
1151 | 1152 | # initialize our GroupByMixin object with
|
1152 | 1153 | # the resampler attributes
|
@@ -1219,7 +1220,10 @@ def _gotitem(self, key, ndim, subset=None):
|
1219 | 1220 | selection = key
|
1220 | 1221 |
|
1221 | 1222 | 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, |
1223 | 1227 | )
|
1224 | 1228 | return new_rs
|
1225 | 1229 |
|
|
0 commit comments