-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: Fix BaseWindowGroupby.aggregate where as_index is ignored #54973
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
Changes from 3 commits
e503c34
ac3c0a1
4d2875b
cbfb7b9
27ce5dc
22bc4f7
0a3bc07
4a1d5bc
4b73bd2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -919,6 +919,12 @@ def _get_window_indexer(self) -> GroupbyIndexer: | |
) | ||
return window_indexer | ||
|
||
@doc(_shared_docs["aggregate"]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't this and below be inherited from the base class? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think so. This was an ugly workaround to a mypy error I was getting but using |
||
def aggregate(self, func, *args, **kwargs): | ||
return super().aggregate(func, *args, **kwargs) | ||
|
||
agg = aggregate | ||
|
||
|
||
class OnlineExponentialMovingWindow(ExponentialMovingWindow): | ||
def __init__( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -875,6 +875,14 @@ def _gotitem(self, key, ndim, subset=None): | |
subset = self.obj.set_index(self._on) | ||
return super()._gotitem(key, ndim, subset=subset) | ||
|
||
def aggregate(self, func, *args, **kwargs): | ||
result = super().aggregate(func, *args, **kwargs) | ||
if not self._as_index: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this should live in |
||
result = result.reset_index(level=list(range(len(self._grouper.names)))) | ||
return result | ||
|
||
agg = aggregate | ||
|
||
|
||
class Window(BaseWindow): | ||
""" | ||
|
@@ -2911,3 +2919,9 @@ def _validate_datetimelike_monotonic(self): | |
f"Each group within {on} must be monotonic. " | ||
f"Sort the values in {on} first." | ||
) | ||
|
||
@doc(_shared_docs["aggregate"]) | ||
def aggregate(self, func, *args, **kwargs): | ||
return super().aggregate(func, *args, **kwargs) | ||
|
||
agg = aggregate |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you write this in terms of public APIs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed this now