diff --git a/pandas/_typing.py b/pandas/_typing.py index 08096569c61a7d..dc51c04447bef3 100644 --- a/pandas/_typing.py +++ b/pandas/_typing.py @@ -328,3 +328,6 @@ def closed(self) -> bool: # plotting PlottingOrientation = Literal["horizontal", "vertical"] + +# dropna +AnyAll = Literal["any", "all"] diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 52b5dd87f58f49..516ed2b1076e10 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -50,6 +50,7 @@ ) from pandas._typing import ( AggFuncType, + AnyAll, AnyArrayLike, ArrayLike, Axes, @@ -6423,7 +6424,7 @@ def dropna( self, *, axis: Axis = ..., - how: Literal["any", "all"] | NoDefault = ..., + how: AnyAll | NoDefault = ..., thresh: int | NoDefault = ..., subset: IndexLabel = ..., inplace: Literal[False] = ..., @@ -6435,7 +6436,7 @@ def dropna( self, *, axis: Axis = ..., - how: Literal["any", "all"] | NoDefault = ..., + how: AnyAll | NoDefault = ..., thresh: int | NoDefault = ..., subset: IndexLabel = ..., inplace: Literal[True], @@ -6446,7 +6447,7 @@ def dropna( def dropna( self, axis: Axis = 0, - how: Literal["any", "all"] | NoDefault = no_default, + how: AnyAll | 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 88f3de52276daa..6da1b22b5a1dcc 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -45,6 +45,7 @@ tz_compare, ) from pandas._typing import ( + AnyAll, ArrayLike, Axes, Dtype, @@ -2971,7 +2972,7 @@ def fillna(self, value=None, downcast=None): ) return self._view() - def dropna(self: _IndexT, how: Literal["any", "all"] = "any") -> _IndexT: + def dropna(self: _IndexT, how: AnyAll = "any") -> _IndexT: """ Return Index without NA/NaN values. diff --git a/pandas/core/indexes/multi.py b/pandas/core/indexes/multi.py index c524a448ae0451..5d751e173fc136 100644 --- a/pandas/core/indexes/multi.py +++ b/pandas/core/indexes/multi.py @@ -29,6 +29,7 @@ ) from pandas._libs.hashtable import duplicated from pandas._typing import ( + AnyAll, AnyArrayLike, DtypeObj, F, @@ -1634,7 +1635,7 @@ def fillna(self, value=None, downcast=None): raise NotImplementedError("isna is not defined for MultiIndex") @doc(Index.dropna) - def dropna(self, how: Literal["any", "all"] = "any") -> MultiIndex: + def dropna(self, how: AnyAll = "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 1978caccec3393..bf313925905f7f 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -35,6 +35,7 @@ from pandas._libs.lib import no_default from pandas._typing import ( AggFuncType, + AnyAll, AnyArrayLike, ArrayLike, Axis, @@ -5735,7 +5736,7 @@ def dropna( *, axis: Axis = ..., inplace: Literal[False] = ..., - how: Literal["any", "all"] | None = ..., + how: AnyAll | None = ..., ) -> Series: ... @@ -5745,7 +5746,7 @@ def dropna( *, axis: Axis = ..., inplace: Literal[True], - how: Literal["any", "all"] | None = ..., + how: AnyAll | None = ..., ) -> None: ... @@ -5754,7 +5755,7 @@ def dropna( self, axis: Axis = 0, inplace: bool = False, - how: Literal["any", "all"] | None = None, + how: AnyAll | None = None, ) -> Series | None: """ Return a new Series with missing values removed.