-
-
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
BUG: Fix BaseWindowGroupby.aggregate where as_index is ignored #54973
Conversation
pandas/core/window/rolling.py
Outdated
@@ -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 comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should live in BaseWindowGroupby
so added this aggregate function. After adding, mypy complained about incompatibility of base classes for classes inheriting BaseWindowGroupby
. Adding aggregate function to those solves the issue happy to extend their docs if required or implement another workaround if preferred over this
pandas/core/window/ewm.py
Outdated
@@ -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 comment
The 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 comment
The 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 type: ignore[misc]
instead now
doc/source/whatsnew/v2.2.0.rst
Outdated
@@ -168,6 +168,7 @@ Performance improvements | |||
Bug fixes | |||
~~~~~~~~~ | |||
- Bug in :class:`AbstractHolidayCalendar` where timezone data was not propagated when computing holiday observances (:issue:`54580`) | |||
- Bug in :meth:`BaseWindowGroupby.aggregate` where ``_as_index`` attribute is ignored (:issue:`31007`) |
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
Also realized that this is failing with a list-like parameter as well so extended testing |
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.
I think this might need some more discussion before implementing; I've put some thoughts in the corresponding issue.
doc/source/whatsnew/v2.2.0.rst
file if fixing a bug or adding a new feature.