Skip to content

REF: Resampler subclasses remove unused arg, ensure parent is not None #51163

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
Feb 4, 2023
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: 9 additions & 5 deletions pandas/core/resample.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
Callable,
Hashable,
Literal,
cast,
final,
no_type_check,
)
Expand Down Expand Up @@ -479,7 +480,7 @@ def _get_resampler_for_grouping(self, groupby, key=None):
"""
Return the correct class for resampling with groupby.
"""
return self._resampler_for_grouping(self, groupby=groupby, key=key)
return self._resampler_for_grouping(groupby=groupby, key=key, parent=self)

def _wrap_result(self, result):
"""
Expand Down Expand Up @@ -1155,11 +1156,11 @@ class _GroupByMixin(PandasObject):
_attributes: list[str] # in practice the same as Resampler._attributes
_selection: IndexLabel | None = None

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

if parent is None:
parent = obj
# parent is always a Resampler, sometimes a _GroupByMixin
assert isinstance(parent, Resampler), type(parent)

# initialize our GroupByMixin object with
# the resampler attributes
Expand Down Expand Up @@ -1232,7 +1233,10 @@ def _gotitem(self, key, ndim, subset=None):
selection = key

new_rs = type(self)(
subset, groupby=groupby, parent=self, selection=selection, **kwargs
groupby=groupby,
parent=cast(Resampler, self),
selection=selection,
**kwargs,
)
return new_rs

Expand Down