Skip to content

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

Closed

Conversation

ihsansecer
Copy link
Contributor

@ihsansecer ihsansecer commented Sep 2, 2023

@@ -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:
Copy link
Contributor Author

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

@@ -919,6 +919,12 @@ def _get_window_indexer(self) -> GroupbyIndexer:
)
return window_indexer

@doc(_shared_docs["aggregate"])
Copy link
Member

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?

Copy link
Contributor Author

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

@@ -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`)
Copy link
Member

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed this now

@mroeschke mroeschke added Groupby Apply Apply, Aggregate, Transform, Map Window rolling, ewma, expanding labels Sep 5, 2023
@ihsansecer
Copy link
Contributor Author

Also realized that this is failing with a list-like parameter as well so extended testing

Copy link
Member

@rhshadrach rhshadrach left a 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Apply Apply, Aggregate, Transform, Map Groupby Window rolling, ewma, expanding
Projects
None yet
Development

Successfully merging this pull request may close these issues.

as_index = False not working for applying groupby rolling agg to DataFrame
3 participants