-
-
Notifications
You must be signed in to change notification settings - Fork 143
Fix groupby.apply() and sum(axis=1) #168
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 all commits
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 | ||
---|---|---|---|---|
|
@@ -3,6 +3,7 @@ from __future__ import annotations | |||
from typing import ( | ||||
Any, | ||||
Callable, | ||||
Iterable, | ||||
Iterator, | ||||
Literal, | ||||
NamedTuple, | ||||
|
@@ -111,7 +112,17 @@ class _DataFrameGroupByNonScalar(DataFrameGroupBy): | |||
class DataFrameGroupBy(GroupBy): | ||||
def any(self, skipna: bool = ...) -> DataFrame: ... | ||||
def all(self, skipna: bool = ...) -> DataFrame: ... | ||||
def apply(self, func, *args, **kwargs) -> DataFrame: ... | ||||
# mypy sees the two overloads as overlapping | ||||
@overload | ||||
def apply( # type: ignore[misc] | ||||
self, func: Callable[[DataFrame], Series | Scalar], *args, **kwargs | ||||
) -> Series: ... | ||||
@overload | ||||
def apply( # type: ignore[misc] | ||||
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 replaced my local version of generic.pyi with this one and it seems that neither pyright nor mypy need these two ignores (I would have thought both of them need ignores, a DataFrame is Iterable). 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. If I remove both of these ignores, I get errors from both 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. you are right, not sure what I messed up. Unless you add a test covering this second overload, I would be tempted to remove it. 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.
There is a test already. That's why I needed to add the second overload. pandas-stubs/tests/test_frame.py Line 558 in 77b357f
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. Okay, I'm not a fan of this overload but it seems to work :) |
||||
self, func: Callable[[Iterable], Series | Scalar], *args, **kwargs | ||||
) -> DataFrame: ... | ||||
@overload | ||||
def apply(self, func: Callable, *args, **kwargs) -> DataFrame | Series: ... | ||||
@overload | ||||
def aggregate(self, arg: str, *args, **kwargs) -> DataFrame: ... | ||||
@overload | ||||
|
Uh oh!
There was an error while loading. Please reload this page.