-
-
Notifications
You must be signed in to change notification settings - Fork 18.6k
TYP: misc return types #57430
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
TYP: misc return types #57430
Conversation
@@ -11815,19 +11899,19 @@ def kurt( | |||
product = prod | |||
|
|||
@doc(make_doc("cummin", ndim=2)) | |||
def cummin(self, axis: Axis | None = None, skipna: bool = True, *args, **kwargs): | |||
def cummin(self, axis: Axis = 0, skipna: bool = True, *args, **kwargs) -> Self: |
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.
None
is not documented and 0
seems to behave the same?!
@property | ||
def _constructor(self) -> Callable[..., Self]: | ||
def _constructor(self) -> Callable[..., Self]: # type: ignore[override] |
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.
Should technically be type[Self]
but the NDFrame constructor allows far fewer arguments than the Series/DataFrame constructor, which leads to many errors when _constructor()(...)
is called inside NDFrame, which are at runtime only reached by sub-classes.
@@ -118,6 +118,7 @@ | |||
Concatenate: Any = None | |||
|
|||
HashableT = TypeVar("HashableT", bound=Hashable) | |||
HashableT2 = TypeVar("HashableT2", bound=Hashable) |
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.
Curious why we need a second one?
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.
needed for _from_nested_dict
. When using the same TypeVar in a function signature, the type checkers bind these to the same type:
def (x: HashableT) -> HashableT: ...
x(None) # return None
x((1, 2, 3)) # return tuple[int, int, int]
When we have a function that tries to bind two different sets of types, we need a new TypeVar
def (x: HashableT, y: HashableT2) -> dict[HashableT, dict[HashableT2, Any]]: ...
(pandas-stubs uses the name HashableT2)
Thanks @twoertwein |
No description provided.