-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
ENH: Add typing for pandas.core.frame.dropna #38968
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 4 commits
5d24561
f2733e3
f2e2bcf
63d0410
bc0c5d2
55ef7f9
5480288
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 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -5070,14 +5070,38 @@ def notna(self) -> DataFrame: | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
def notnull(self) -> DataFrame: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return ~self.isna() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
# Overload function signature to prevent union of conflicting types | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
# As Optional[DataFrame] is really Union[DataFrame, None] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
@overload | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
def dropna( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
self, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
axis: Axis = ..., | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
how: str = ..., | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
thresh: Optional[int] = ..., | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
subset: Optional[Union[Hashable, Sequence[Hashable]]] = ..., | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
inplace: Literal[False] = False, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
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. should you be specifying the default value here? (I'm not sure) 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. Looks like we were typing at the time :P My understanding of overloading (and this might be very wrong) is that you only specify the defaults in overloads for those parameters you are overloading, in this case See below for an example taken from Lines 4812 to 4843 in 67d4cae
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. yeah in this example the defaults are not specified in the overloaded signatures so I think you should get rid of those 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. That example also explains the mypy error (it's caused to a mypy bug). So to get mypy passing you need to add a type ignore (and a comment with the link to mypy issue and the error message above the overloaded signature as done in the Those things being done I think this will be good to go in 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. Gotcha! Changes forthcoming... |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
) -> DataFrame: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
@overload | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
def dropna( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
self, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
axis: Axis = ..., | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
how: str = ..., | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
thresh: Optional[int] = ..., | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
subset: Optional[Union[Hashable, Sequence[Hashable]]] = ..., | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
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. we now have an
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
inplace: Literal[True] = True, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
) -> None: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
def dropna( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
self, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
axis: Axis = 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
how: str = "any", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
thresh=None, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
subset=None, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
thresh: Optional[int] = None, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
subset: Optional[Union[Hashable, Sequence[Hashable]]] = None, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
inplace: bool = False, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
) -> Optional[DataFrame]: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
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 see you used #37137 as a example. However the motivation for that PR was to remove an Not needed to be done in this PR, but just FYI if the motivation for adding the types is for the public api, then the return type should be the same type as self for subclassed DataFrames. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
""" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Remove missing values. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -5216,6 +5240,7 @@ def dropna( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if inplace: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
self._update_inplace(result) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return None | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
else: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return result | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
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'd drop this comment