From e5a32ca0e814933a74634b2d6db4647de58815ac Mon Sep 17 00:00:00 2001 From: Patrick Hoefler Date: Sun, 28 Aug 2022 13:48:33 +0200 Subject: [PATCH] TYP: Specify how in dropna --- pandas/core/frame.py | 6 +++--- pandas/core/indexes/base.py | 2 +- pandas/core/indexes/multi.py | 2 +- pandas/core/series.py | 17 ++++++++++++++--- 4 files changed, 19 insertions(+), 8 deletions(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 4302b14da6418..52b5dd87f58f4 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -6423,7 +6423,7 @@ def dropna( self, *, axis: Axis = ..., - how: str | NoDefault = ..., + how: Literal["any", "all"] | NoDefault = ..., thresh: int | NoDefault = ..., subset: IndexLabel = ..., inplace: Literal[False] = ..., @@ -6435,7 +6435,7 @@ def dropna( self, *, axis: Axis = ..., - how: str | NoDefault = ..., + how: Literal["any", "all"] | NoDefault = ..., thresh: int | NoDefault = ..., subset: IndexLabel = ..., inplace: Literal[True], @@ -6446,7 +6446,7 @@ def dropna( def dropna( self, axis: Axis = 0, - how: str | NoDefault = no_default, + how: Literal["any", "all"] | NoDefault = no_default, thresh: int | NoDefault = no_default, subset: IndexLabel = None, inplace: bool = False, diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index 91c658a4cef5d..88f3de52276da 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -2971,7 +2971,7 @@ def fillna(self, value=None, downcast=None): ) return self._view() - def dropna(self: _IndexT, how: str_t = "any") -> _IndexT: + def dropna(self: _IndexT, how: Literal["any", "all"] = "any") -> _IndexT: """ Return Index without NA/NaN values. diff --git a/pandas/core/indexes/multi.py b/pandas/core/indexes/multi.py index 63c78b7002786..c524a448ae045 100644 --- a/pandas/core/indexes/multi.py +++ b/pandas/core/indexes/multi.py @@ -1634,7 +1634,7 @@ def fillna(self, value=None, downcast=None): raise NotImplementedError("isna is not defined for MultiIndex") @doc(Index.dropna) - def dropna(self, how: str = "any") -> MultiIndex: + def dropna(self, how: Literal["any", "all"] = "any") -> MultiIndex: nans = [level_codes == -1 for level_codes in self.codes] if how == "any": indexer = np.any(nans, axis=0) diff --git a/pandas/core/series.py b/pandas/core/series.py index d2f66e9bd36e2..1978caccec339 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -5731,19 +5731,30 @@ def notnull(self) -> Series: @overload def dropna( - self, *, axis: Axis = ..., inplace: Literal[False] = ..., how: str | None = ... + self, + *, + axis: Axis = ..., + inplace: Literal[False] = ..., + how: Literal["any", "all"] | None = ..., ) -> Series: ... @overload def dropna( - self, *, axis: Axis = ..., inplace: Literal[True], how: str | None = ... + self, + *, + axis: Axis = ..., + inplace: Literal[True], + how: Literal["any", "all"] | None = ..., ) -> None: ... @deprecate_nonkeyword_arguments(version=None, allowed_args=["self"]) def dropna( - self, axis: Axis = 0, inplace: bool = False, how: str | None = None + self, + axis: Axis = 0, + inplace: bool = False, + how: Literal["any", "all"] | None = None, ) -> Series | None: """ Return a new Series with missing values removed.