-
-
Notifications
You must be signed in to change notification settings - Fork 18.6k
TYP overload fillna #40737 #40887
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 overload fillna #40737 #40887
Changes from 9 commits
79f6b50
9b6966a
fce2d11
bd93f31
16b42e7
2ab41f8
d6cc081
a641df2
45cc60c
1c33bd5
b6a4fac
2adcaf7
4b7744e
0c3d28d
1c8dd1a
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 |
---|---|---|
|
@@ -5007,6 +5007,354 @@ def rename( | |
errors=errors, | ||
) | ||
|
||
@overload | ||
def fillna( | ||
self, | ||
value: Scalar | dict | Series | DataFrame | None = ..., | ||
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. can we make an alias for this |
||
method: str | None = ..., | ||
axis: Axis | None = ..., | ||
inplace: Literal[False] = ..., | ||
limit: int | None = ..., | ||
downcast: dict | str | None = ..., | ||
) -> DataFrame: | ||
... | ||
|
||
@overload | ||
def fillna( | ||
self, | ||
value: Scalar | dict | Series | DataFrame | None, | ||
method: str | None, | ||
axis: Axis | None, | ||
inplace: Literal[True], | ||
limit: int | None, | ||
downcast: dict | str | None, | ||
) -> None: | ||
... | ||
|
||
@overload | ||
def fillna( | ||
self, | ||
*, | ||
inplace: Literal[True], | ||
) -> None: | ||
... | ||
|
||
@overload | ||
def fillna( | ||
self, | ||
value: Scalar | dict | Series | DataFrame | None, | ||
*, | ||
inplace: Literal[True], | ||
) -> None: | ||
... | ||
|
||
@overload | ||
def fillna( | ||
self, | ||
*, | ||
method: str | None, | ||
inplace: Literal[True], | ||
) -> None: | ||
... | ||
|
||
@overload | ||
def fillna( | ||
self, | ||
*, | ||
axis: Axis | None, | ||
inplace: Literal[True], | ||
) -> None: | ||
... | ||
|
||
@overload | ||
def fillna( | ||
self, | ||
*, | ||
inplace: Literal[True], | ||
downcast: dict | str | None, | ||
) -> None: | ||
... | ||
|
||
@overload | ||
def fillna( | ||
self, | ||
value: Scalar | dict | Series | DataFrame | None, | ||
method: str | None, | ||
*, | ||
inplace: Literal[True], | ||
) -> None: | ||
... | ||
|
||
@overload | ||
def fillna( | ||
self, | ||
value: Scalar | dict | Series | DataFrame | None, | ||
*, | ||
axis: Axis | None, | ||
inplace: Literal[True], | ||
) -> None: | ||
... | ||
|
||
@overload | ||
def fillna( | ||
self, | ||
value: Scalar | dict | Series | DataFrame | None, | ||
*, | ||
inplace: Literal[True], | ||
limit: int | None, | ||
) -> None: | ||
... | ||
|
||
@overload | ||
def fillna( | ||
self, | ||
value: Scalar | dict | Series | DataFrame | None, | ||
*, | ||
inplace: Literal[True], | ||
downcast: dict | str | None, | ||
) -> None: | ||
... | ||
|
||
@overload | ||
def fillna( | ||
self, | ||
*, | ||
method: str | None, | ||
axis: Axis | None, | ||
inplace: Literal[True], | ||
) -> None: | ||
... | ||
|
||
@overload | ||
def fillna( | ||
self, | ||
*, | ||
method: str | None, | ||
inplace: Literal[True], | ||
limit: int | None, | ||
) -> None: | ||
... | ||
|
||
@overload | ||
def fillna( | ||
self, | ||
*, | ||
method: str | None, | ||
inplace: Literal[True], | ||
downcast: dict | str | None, | ||
) -> None: | ||
... | ||
|
||
@overload | ||
def fillna( | ||
self, | ||
*, | ||
axis: Axis | None, | ||
inplace: Literal[True], | ||
limit: int | None, | ||
) -> None: | ||
... | ||
|
||
@overload | ||
def fillna( | ||
self, | ||
*, | ||
axis: Axis | None, | ||
inplace: Literal[True], | ||
downcast: dict | str | None, | ||
) -> None: | ||
... | ||
|
||
@overload | ||
def fillna( | ||
self, | ||
*, | ||
inplace: Literal[True], | ||
limit: int | None, | ||
downcast: dict | str | None, | ||
) -> None: | ||
... | ||
|
||
@overload | ||
def fillna( | ||
self, | ||
value: Scalar | dict | Series | DataFrame | None, | ||
method: str | None, | ||
axis: Axis | None, | ||
inplace: Literal[True], | ||
) -> None: | ||
... | ||
|
||
@overload | ||
def fillna( | ||
self, | ||
value: Scalar | dict | Series | DataFrame | None, | ||
method: str | None, | ||
*, | ||
inplace: Literal[True], | ||
limit: int | None, | ||
) -> None: | ||
... | ||
|
||
@overload | ||
def fillna( | ||
self, | ||
value: Scalar | dict | Series | DataFrame | None, | ||
method: str | None, | ||
*, | ||
inplace: Literal[True], | ||
downcast: dict | str | None, | ||
) -> None: | ||
... | ||
|
||
@overload | ||
def fillna( | ||
self, | ||
value: Scalar | dict | Series | DataFrame | None, | ||
*, | ||
axis: Axis | None, | ||
inplace: Literal[True], | ||
limit: int | None, | ||
) -> None: | ||
... | ||
|
||
@overload | ||
def fillna( | ||
self, | ||
value: Scalar | dict | Series | DataFrame | None, | ||
*, | ||
axis: Axis | None, | ||
inplace: Literal[True], | ||
downcast: dict | str | None, | ||
) -> None: | ||
... | ||
|
||
@overload | ||
def fillna( | ||
self, | ||
value: Scalar | dict | Series | DataFrame | None, | ||
*, | ||
inplace: Literal[True], | ||
limit: int | None, | ||
downcast: dict | str | None, | ||
) -> None: | ||
... | ||
|
||
@overload | ||
def fillna( | ||
self, | ||
*, | ||
method: str | None, | ||
axis: Axis | None, | ||
inplace: Literal[True], | ||
limit: int | None, | ||
) -> None: | ||
... | ||
|
||
@overload | ||
def fillna( | ||
self, | ||
*, | ||
method: str | None, | ||
axis: Axis | None, | ||
inplace: Literal[True], | ||
downcast: dict | str | None, | ||
) -> None: | ||
... | ||
|
||
@overload | ||
def fillna( | ||
self, | ||
*, | ||
method: str | None, | ||
inplace: Literal[True], | ||
limit: int | None, | ||
downcast: dict | str | None, | ||
) -> None: | ||
... | ||
|
||
@overload | ||
def fillna( | ||
self, | ||
*, | ||
axis: Axis | None, | ||
inplace: Literal[True], | ||
limit: int | None, | ||
downcast: dict | str | None, | ||
) -> None: | ||
... | ||
|
||
@overload | ||
def fillna( | ||
self, | ||
*, | ||
method: str | None, | ||
axis: Axis | None, | ||
inplace: Literal[True], | ||
limit: int | None, | ||
downcast: dict | str | None, | ||
) -> None: | ||
... | ||
|
||
@overload | ||
def fillna( | ||
self, | ||
value: Scalar | dict | Series | DataFrame | None, | ||
*, | ||
axis: Axis | None, | ||
inplace: Literal[True], | ||
limit: int | None, | ||
downcast: dict | str | None, | ||
) -> None: | ||
... | ||
|
||
@overload | ||
def fillna( | ||
self, | ||
value: Scalar | dict | Series | DataFrame | None, | ||
method: str | None, | ||
*, | ||
inplace: Literal[True], | ||
limit: int | None, | ||
downcast: dict | str | None, | ||
) -> None: | ||
... | ||
|
||
@overload | ||
def fillna( | ||
self, | ||
value: Scalar | dict | Series | DataFrame | None, | ||
method: str | None, | ||
axis: Axis | None, | ||
inplace: Literal[True], | ||
*, | ||
downcast: dict | str | None, | ||
) -> None: | ||
... | ||
|
||
@overload | ||
def fillna( | ||
self, | ||
value: Scalar | dict | Series | DataFrame | None, | ||
method: str | None, | ||
axis: Axis | None, | ||
inplace: Literal[True], | ||
limit: int | None, | ||
) -> None: | ||
... | ||
|
||
@overload | ||
def fillna( | ||
self, | ||
value: Scalar | dict | Series | DataFrame | None = ..., | ||
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've typed 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 can modify it, but let's wait until someone has confirmed the typing of 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. @LarWong perhaps let's revert typing 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. @MarcoGorelli Sorry, but I'm not sure what you mean by revert typing. Do you mean:
As in not typing 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. Exactly 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. @MarcoGorelli Ok done! The outputs from |
||
method: str | None = ..., | ||
axis: Axis | None = ..., | ||
inplace: bool = ..., | ||
limit: int | None = ..., | ||
downcast: dict | str | None = ..., | ||
) -> DataFrame | None: | ||
... | ||
|
||
@doc(NDFrame.fillna, **_shared_doc_kwargs) | ||
def fillna( | ||
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.
can we not put these in .pyi?
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 was told to add them directly to these files since existing overloads were already there
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.
@jreback yes, that would be great! Thing is though, the
.pyi
files require you to define all methods of a moduleGiven the sheer number of methods this module has, I'd suggest taking this PR with the overloads here, and then moving the overloads (along with annotations for all other methods) to a
pandas/core/frame.pyi
fileThere 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.
@LarWong I'll get back to you on typing
value
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 don't think we want to go the route of using stubs for python files
not that I think it should be done here, but it is possible to partially type a module using stubs.
https://github.com/python/typeshed/blob/master/CONTRIBUTING.md#incomplete-stubs
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.
Thanks @simonjayhawkins , didn't know that was possible. Why not use partial stubs for overloads? Because some methods, like
Series.drop
pandas/pandas/core/series.py
Lines 4478 to 4487 in 84d9c5e
have 5 (five!) arguments with defaults before
inplace
, leading to...34 overloads 🤯 ! And even if we disallowedlabels
being passed asNone
in that one, that would still leave us with 18 overloads!For typing
value
here, do you thinkScalar | Mapping[Hashable, Scalar] | Series | DataFrame | None
would be correct?Uh oh!
There was an error while loading. Please reload this page.
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.
The problem is that if a stub file is present it takes precedence over the python file. so we cannot ensure internal consistency and need to duplicate the type annotations to be able to check the functions in the module itself.
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 we are planning to to drop the inplace argument, hopefully pandas 2.0 and we won't need all these overloads. #16529