From 0568d57932c6fd72116b9d4b9e744500c4042a72 Mon Sep 17 00:00:00 2001 From: Irv Lustig Date: Sat, 1 May 2021 19:14:44 -0400 Subject: [PATCH 1/9] TYP: Simple type fixes for ExtensionArray --- pandas/core/arrays/base.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/pandas/core/arrays/base.py b/pandas/core/arrays/base.py index 5a2643dd531ed..62f148a68857d 100644 --- a/pandas/core/arrays/base.py +++ b/pandas/core/arrays/base.py @@ -13,6 +13,7 @@ TYPE_CHECKING, Any, Callable, + Iterator, Sequence, TypeVar, cast, @@ -69,6 +70,7 @@ ) if TYPE_CHECKING: + from typing import Literal class ExtensionArraySupportsAnyAll("ExtensionArray"): def any(self, *, skipna: bool = True) -> bool: @@ -375,7 +377,7 @@ def __len__(self) -> int: """ raise AbstractMethodError(self) - def __iter__(self): + def __iter__(self) -> Iterator[Any]: """ Iterate over elements of the array. """ @@ -385,7 +387,7 @@ def __iter__(self): for i in range(len(self)): yield self[i] - def __contains__(self, item) -> bool | np.bool_: + def __contains__(self, item: Any) -> bool | np.bool_: """ Return for `item in self`. """ @@ -680,7 +682,12 @@ def argmax(self, skipna: bool = True) -> int: raise NotImplementedError return nargminmax(self, "argmax") - def fillna(self, value=None, method=None, limit=None): + def fillna( + self, + value: Any | ArrayLike | None, + method: Literal["backfill", "bfill", "ffill", "pad"] | None = None, + limit: int | None = None, + ): """ Fill NA/NaN values using the specified method. @@ -1207,7 +1214,7 @@ def _formatter(self, boxed: bool = False) -> Callable[[Any], str | None]: # Reshaping # ------------------------------------------------------------------------ - def transpose(self, *axes) -> ExtensionArray: + def transpose(self, *axes: int) -> ExtensionArray: """ Return a transposed view on this array. @@ -1220,7 +1227,7 @@ def transpose(self, *axes) -> ExtensionArray: def T(self) -> ExtensionArray: return self.transpose() - def ravel(self, order="C") -> ExtensionArray: + def ravel(self, order: Literal["C", "F", "A", "K"] | None = "C") -> ExtensionArray: """ Return a flattened view on this array. @@ -1294,7 +1301,7 @@ def _reduce(self, name: str, *, skipna: bool = True, **kwargs): """ raise TypeError(f"cannot perform {name} with type {self.dtype}") - def __hash__(self): + def __hash__(self) -> int: raise TypeError(f"unhashable type: {repr(type(self).__name__)}") # ------------------------------------------------------------------------ From ca0ba554853b7674d90474ed5137324807f61c89 Mon Sep 17 00:00:00 2001 From: Irv Lustig Date: Sat, 1 May 2021 20:02:45 -0400 Subject: [PATCH 2/9] fix fillna value default arg --- pandas/core/arrays/base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/arrays/base.py b/pandas/core/arrays/base.py index 62f148a68857d..5e7cf2bb05b9a 100644 --- a/pandas/core/arrays/base.py +++ b/pandas/core/arrays/base.py @@ -684,7 +684,7 @@ def argmax(self, skipna: bool = True) -> int: def fillna( self, - value: Any | ArrayLike | None, + value: Any | ArrayLike | None = None, method: Literal["backfill", "bfill", "ffill", "pad"] | None = None, limit: int | None = None, ): From 7e46ad29a5d6c2aac9a5e2cd301d9bc22a5097b6 Mon Sep 17 00:00:00 2001 From: Irv Lustig Date: Sun, 2 May 2021 10:08:02 -0400 Subject: [PATCH 3/9] specify args for transpose --- pandas/core/arrays/base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/arrays/base.py b/pandas/core/arrays/base.py index 5e7cf2bb05b9a..abbb85d5ade3f 100644 --- a/pandas/core/arrays/base.py +++ b/pandas/core/arrays/base.py @@ -1214,7 +1214,7 @@ def _formatter(self, boxed: bool = False) -> Callable[[Any], str | None]: # Reshaping # ------------------------------------------------------------------------ - def transpose(self, *axes: int) -> ExtensionArray: + def transpose(self, *axes: tuple[int] | list[int] | None) -> ExtensionArray: """ Return a transposed view on this array. From 30b6dcb9d42cebf31f807541b27fcf5ebd86284c Mon Sep 17 00:00:00 2001 From: Irv Lustig Date: Sun, 2 May 2021 19:51:50 -0400 Subject: [PATCH 4/9] update transpose and fillna to use consistent typing --- pandas/_typing.py | 1 + pandas/core/arrays/base.py | 3 ++- pandas/core/base.py | 5 +++-- pandas/core/frame.py | 23 ++++++++++++----------- pandas/core/series.py | 16 ++++++++-------- 5 files changed, 26 insertions(+), 22 deletions(-) diff --git a/pandas/_typing.py b/pandas/_typing.py index a58dc0dba1bf1..08e462e8db237 100644 --- a/pandas/_typing.py +++ b/pandas/_typing.py @@ -112,6 +112,7 @@ FrameOrSeries = TypeVar("FrameOrSeries", bound="NDFrame") Axis = Union[str, int] +NumpyAxis = Union[Tuple[int], List[int], None] IndexLabel = Union[Hashable, Sequence[Hashable]] Level = Union[Hashable, int] Shape = Tuple[int, ...] diff --git a/pandas/core/arrays/base.py b/pandas/core/arrays/base.py index abbb85d5ade3f..65d9edc523059 100644 --- a/pandas/core/arrays/base.py +++ b/pandas/core/arrays/base.py @@ -25,6 +25,7 @@ from pandas._typing import ( ArrayLike, Dtype, + NumpyAxis, PositionalIndexer, Shape, ) @@ -1214,7 +1215,7 @@ def _formatter(self, boxed: bool = False) -> Callable[[Any], str | None]: # Reshaping # ------------------------------------------------------------------------ - def transpose(self, *axes: tuple[int] | list[int] | None) -> ExtensionArray: + def transpose(self, axes: NumpyAxis = None) -> ExtensionArray: """ Return a transposed view on this array. diff --git a/pandas/core/base.py b/pandas/core/base.py index 42f52618eb07b..5f6a2c25cab6c 100644 --- a/pandas/core/base.py +++ b/pandas/core/base.py @@ -19,6 +19,7 @@ Dtype, DtypeObj, IndexLabel, + NumpyAxis, Shape, final, ) @@ -298,7 +299,7 @@ def _values(self) -> ExtensionArray | np.ndarray: # must be defined here as a property for mypy raise AbstractMethodError(self) - def transpose(self: _T, *args, **kwargs) -> _T: + def transpose(self: _T, axes: NumpyAxis = None) -> _T: """ Return the transpose, which is by definition self. @@ -306,7 +307,7 @@ def transpose(self: _T, *args, **kwargs) -> _T: ------- %(klass)s """ - nv.validate_transpose(args, kwargs) + nv.validate_transpose(axes, {}) return self T = property( diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 4469869a5a929..1cc6a2f38d5c1 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -62,6 +62,7 @@ IndexLabel, Level, NpDtype, + NumpyAxis, PythonFuncType, Renamer, Scalar, @@ -3189,7 +3190,7 @@ def memory_usage(self, index: bool = True, deep: bool = False) -> Series: ).append(result) return result - def transpose(self, *args, copy: bool = False) -> DataFrame: + def transpose(self, axes: NumpyAxis = None, copy: bool = False) -> DataFrame: """ Transpose index and columns. @@ -3199,7 +3200,7 @@ def transpose(self, *args, copy: bool = False) -> DataFrame: Parameters ---------- - *args : tuple, optional + axes : tuple or list, optional Accepted for compatibility with NumPy. copy : bool, default False Whether to copy the data after transposing, even for DataFrames @@ -3286,7 +3287,7 @@ def transpose(self, *args, copy: bool = False) -> DataFrame: 1 object dtype: object """ - nv.validate_transpose(args, {}) + nv.validate_transpose(axes, {}) # construct the args dtypes = list(self.dtypes) @@ -5015,7 +5016,7 @@ def rename( def fillna( self, value=..., - method: str | None = ..., + method: Literal["backfill", "bfill", "ffill", "pad"] | None = ..., axis: Axis | None = ..., inplace: Literal[False] = ..., limit=..., @@ -5027,7 +5028,7 @@ def fillna( def fillna( self, value, - method: str | None, + method: Literal["backfill", "bfill", "ffill", "pad"] | None, axis: Axis | None, inplace: Literal[True], limit=..., @@ -5060,7 +5061,7 @@ def fillna( def fillna( self, *, - method: str | None, + method: Literal["backfill", "bfill", "ffill", "pad"] | None, inplace: Literal[True], limit=..., downcast=..., @@ -5082,7 +5083,7 @@ def fillna( def fillna( self, *, - method: str | None, + method: Literal["backfill", "bfill", "ffill", "pad"] | None, axis: Axis | None, inplace: Literal[True], limit=..., @@ -5106,7 +5107,7 @@ def fillna( def fillna( self, value, - method: str | None, + method: Literal["backfill", "bfill", "ffill", "pad"] | None, *, inplace: Literal[True], limit=..., @@ -5118,7 +5119,7 @@ def fillna( def fillna( self, value=..., - method: str | None = ..., + method: Literal["backfill", "bfill", "ffill", "pad"] | None = ..., axis: Axis | None = ..., inplace: bool = ..., limit=..., @@ -5129,8 +5130,8 @@ def fillna( @doc(NDFrame.fillna, **_shared_doc_kwargs) def fillna( self, - value=None, - method: str | None = None, + value: Any | ArrayLike | None = None, + method: Literal["backfill", "bfill", "ffill", "pad"] | None = None, axis: Axis | None = None, inplace: bool = False, limit=None, diff --git a/pandas/core/series.py b/pandas/core/series.py index 6a3e997a58754..bf73f7a116609 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -4594,7 +4594,7 @@ def drop( def fillna( self, value=..., - method: str | None = ..., + method: Literal["backfill", "bfill", "ffill", "pad"] | None = ..., axis: Axis | None = ..., inplace: Literal[False] = ..., limit=..., @@ -4606,7 +4606,7 @@ def fillna( def fillna( self, value, - method: str | None, + method: Literal["backfill", "bfill", "ffill", "pad"] | None, axis: Axis | None, inplace: Literal[True], limit=..., @@ -4639,7 +4639,7 @@ def fillna( def fillna( self, *, - method: str | None, + method: Literal["backfill", "bfill", "ffill", "pad"] | None, inplace: Literal[True], limit=..., downcast=..., @@ -4661,7 +4661,7 @@ def fillna( def fillna( self, *, - method: str | None, + method: Literal["backfill", "bfill", "ffill", "pad"] | None, axis: Axis | None, inplace: Literal[True], limit=..., @@ -4685,7 +4685,7 @@ def fillna( def fillna( self, value, - method: str | None, + method: Literal["backfill", "bfill", "ffill", "pad"] | None, *, inplace: Literal[True], limit=..., @@ -4697,7 +4697,7 @@ def fillna( def fillna( self, value=..., - method: str | None = ..., + method: Literal["backfill", "bfill", "ffill", "pad"] | None = ..., axis: Axis | None = ..., inplace: bool = ..., limit=..., @@ -4709,8 +4709,8 @@ def fillna( @doc(NDFrame.fillna, **_shared_doc_kwargs) # type: ignore[has-type] def fillna( self, - value=None, - method=None, + value: Any | ArrayLike | None = None, + method: Literal["backfill", "bfill", "ffill", "pad"] | None = None, axis=None, inplace=False, limit=None, From ee12178704f741725b839d0c76571781e87f314b Mon Sep 17 00:00:00 2001 From: Irv Lustig Date: Sun, 2 May 2021 21:24:20 -0400 Subject: [PATCH 5/9] undo change to transpose in core/base.py --- pandas/core/base.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/pandas/core/base.py b/pandas/core/base.py index 5f6a2c25cab6c..42f52618eb07b 100644 --- a/pandas/core/base.py +++ b/pandas/core/base.py @@ -19,7 +19,6 @@ Dtype, DtypeObj, IndexLabel, - NumpyAxis, Shape, final, ) @@ -299,7 +298,7 @@ def _values(self) -> ExtensionArray | np.ndarray: # must be defined here as a property for mypy raise AbstractMethodError(self) - def transpose(self: _T, axes: NumpyAxis = None) -> _T: + def transpose(self: _T, *args, **kwargs) -> _T: """ Return the transpose, which is by definition self. @@ -307,7 +306,7 @@ def transpose(self: _T, axes: NumpyAxis = None) -> _T: ------- %(klass)s """ - nv.validate_transpose(axes, {}) + nv.validate_transpose(args, kwargs) return self T = property( From 4b9bd1ec210e82de69cdae1cd2573e6c9f694d61 Mon Sep 17 00:00:00 2001 From: Irv Lustig Date: Sun, 2 May 2021 22:34:35 -0400 Subject: [PATCH 6/9] fix transpose to use axes argument --- pandas/core/base.py | 7 +++++-- pandas/tests/generic/test_generic.py | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/pandas/core/base.py b/pandas/core/base.py index 42f52618eb07b..57199ca151b20 100644 --- a/pandas/core/base.py +++ b/pandas/core/base.py @@ -19,6 +19,7 @@ Dtype, DtypeObj, IndexLabel, + NumpyAxis, Shape, final, ) @@ -298,7 +299,7 @@ def _values(self) -> ExtensionArray | np.ndarray: # must be defined here as a property for mypy raise AbstractMethodError(self) - def transpose(self: _T, *args, **kwargs) -> _T: + def transpose(self: _T, axes: NumpyAxis = None) -> _T: """ Return the transpose, which is by definition self. @@ -306,7 +307,9 @@ def transpose(self: _T, *args, **kwargs) -> _T: ------- %(klass)s """ - nv.validate_transpose(args, kwargs) + if not (isinstance(axes, list) and isinstance(axes, tuple)): + axes = (axes,) + nv.validate_transpose(axes, {}) return self T = property( diff --git a/pandas/tests/generic/test_generic.py b/pandas/tests/generic/test_generic.py index d07f843f4acfc..565be920a3b6a 100644 --- a/pandas/tests/generic/test_generic.py +++ b/pandas/tests/generic/test_generic.py @@ -405,7 +405,7 @@ def test_numpy_transpose(self, frame_or_series): # round-trip preserved tm.assert_equal(np.transpose(np.transpose(obj)), obj) - msg = "the 'axes' parameter is not supported" + msg = r"(the 'axes' parameter is not supported|axes don't match array)" with pytest.raises(ValueError, match=msg): np.transpose(obj, axes=1) From 488a3dea6afb7280aa5ff0fe9063e27bce7de6f6 Mon Sep 17 00:00:00 2001 From: Irv Lustig Date: Mon, 3 May 2021 06:38:52 -0400 Subject: [PATCH 7/9] typing fix in pandas/core/base.py --- pandas/core/base.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pandas/core/base.py b/pandas/core/base.py index 57199ca151b20..1091c09fdb1b1 100644 --- a/pandas/core/base.py +++ b/pandas/core/base.py @@ -308,8 +308,10 @@ def transpose(self: _T, axes: NumpyAxis = None) -> _T: %(klass)s """ if not (isinstance(axes, list) and isinstance(axes, tuple)): - axes = (axes,) - nv.validate_transpose(axes, {}) + args = (axes,) + else: + args = axes + nv.validate_transpose(args, {}) return self T = property( From 5ccb62ab201bc6fa7b5e8dadd363ead6e43ff4e9 Mon Sep 17 00:00:00 2001 From: Irv Lustig Date: Tue, 4 May 2021 07:44:04 -0400 Subject: [PATCH 8/9] undo transpose changes. Use object for fillna and __contains__ --- pandas/_typing.py | 1 - pandas/core/arrays/base.py | 11 ++++++----- pandas/core/base.py | 9 ++------- pandas/core/frame.py | 9 ++++----- pandas/core/series.py | 2 +- pandas/tests/generic/test_generic.py | 2 +- 6 files changed, 14 insertions(+), 20 deletions(-) diff --git a/pandas/_typing.py b/pandas/_typing.py index 08e462e8db237..a58dc0dba1bf1 100644 --- a/pandas/_typing.py +++ b/pandas/_typing.py @@ -112,7 +112,6 @@ FrameOrSeries = TypeVar("FrameOrSeries", bound="NDFrame") Axis = Union[str, int] -NumpyAxis = Union[Tuple[int], List[int], None] IndexLabel = Union[Hashable, Sequence[Hashable]] Level = Union[Hashable, int] Shape = Tuple[int, ...] diff --git a/pandas/core/arrays/base.py b/pandas/core/arrays/base.py index 7214cdd4ec8ae..5710775f6c89a 100644 --- a/pandas/core/arrays/base.py +++ b/pandas/core/arrays/base.py @@ -25,7 +25,6 @@ from pandas._typing import ( ArrayLike, Dtype, - NumpyAxis, PositionalIndexer, Shape, ) @@ -388,7 +387,7 @@ def __iter__(self) -> Iterator[Any]: for i in range(len(self)): yield self[i] - def __contains__(self, item: Any) -> bool | np.bool_: + def __contains__(self, item: object) -> bool | np.bool_: """ Return for `item in self`. """ @@ -403,7 +402,9 @@ def __contains__(self, item: Any) -> bool | np.bool_: else: return False else: - return (item == self).any() + # error: Item "ExtensionArray" of "Union[ExtensionArray, ndarray]" has no + # attribute "any" + return (item == self).any() # type: ignore[union-attr] # error: Signature of "__eq__" incompatible with supertype "object" def __eq__(self, other: Any) -> ArrayLike: # type: ignore[override] @@ -685,7 +686,7 @@ def argmax(self, skipna: bool = True) -> int: def fillna( self, - value: Any | ArrayLike | None = None, + value: object | ArrayLike | None = None, method: Literal["backfill", "bfill", "ffill", "pad"] | None = None, limit: int | None = None, ): @@ -1215,7 +1216,7 @@ def _formatter(self, boxed: bool = False) -> Callable[[Any], str | None]: # Reshaping # ------------------------------------------------------------------------ - def transpose(self, axes: NumpyAxis = None) -> ExtensionArray: + def transpose(self, *axes: int) -> ExtensionArray: """ Return a transposed view on this array. diff --git a/pandas/core/base.py b/pandas/core/base.py index ccdb88a8a5f8b..3270e3dd82f7d 100644 --- a/pandas/core/base.py +++ b/pandas/core/base.py @@ -20,7 +20,6 @@ Dtype, DtypeObj, IndexLabel, - NumpyAxis, Shape, final, ) @@ -300,7 +299,7 @@ def _values(self) -> ExtensionArray | np.ndarray: # must be defined here as a property for mypy raise AbstractMethodError(self) - def transpose(self: _T, axes: NumpyAxis = None) -> _T: + def transpose(self: _T, *args, **kwargs) -> _T: """ Return the transpose, which is by definition self. @@ -308,11 +307,7 @@ def transpose(self: _T, axes: NumpyAxis = None) -> _T: ------- %(klass)s """ - if not (isinstance(axes, list) and isinstance(axes, tuple)): - args = (axes,) - else: - args = axes - nv.validate_transpose(args, {}) + nv.validate_transpose(args, kwargs) return self T = property( diff --git a/pandas/core/frame.py b/pandas/core/frame.py index fc9920c5af404..052a7de5ed092 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -62,7 +62,6 @@ IndexLabel, Level, NpDtype, - NumpyAxis, PythonFuncType, Renamer, Scalar, @@ -3190,7 +3189,7 @@ def memory_usage(self, index: bool = True, deep: bool = False) -> Series: ).append(result) return result - def transpose(self, axes: NumpyAxis = None, copy: bool = False) -> DataFrame: + def transpose(self, *args, copy: bool = False) -> DataFrame: """ Transpose index and columns. @@ -3200,7 +3199,7 @@ def transpose(self, axes: NumpyAxis = None, copy: bool = False) -> DataFrame: Parameters ---------- - axes : tuple or list, optional + *args : tuple, optional Accepted for compatibility with NumPy. copy : bool, default False Whether to copy the data after transposing, even for DataFrames @@ -3287,7 +3286,7 @@ def transpose(self, axes: NumpyAxis = None, copy: bool = False) -> DataFrame: 1 object dtype: object """ - nv.validate_transpose(axes, {}) + nv.validate_transpose(args, {}) # construct the args dtypes = list(self.dtypes) @@ -5130,7 +5129,7 @@ def fillna( @doc(NDFrame.fillna, **_shared_doc_kwargs) def fillna( self, - value: Any | ArrayLike | None = None, + value: object | ArrayLike | None = None, method: Literal["backfill", "bfill", "ffill", "pad"] | None = None, axis: Axis | None = None, inplace: bool = False, diff --git a/pandas/core/series.py b/pandas/core/series.py index ee46e86b610f3..dbf55ab7e2d0d 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -4709,7 +4709,7 @@ def fillna( @doc(NDFrame.fillna, **_shared_doc_kwargs) # type: ignore[has-type] def fillna( self, - value: Any | ArrayLike | None = None, + value: object | ArrayLike | None = None, method: Literal["backfill", "bfill", "ffill", "pad"] | None = None, axis=None, inplace=False, diff --git a/pandas/tests/generic/test_generic.py b/pandas/tests/generic/test_generic.py index 565be920a3b6a..d07f843f4acfc 100644 --- a/pandas/tests/generic/test_generic.py +++ b/pandas/tests/generic/test_generic.py @@ -405,7 +405,7 @@ def test_numpy_transpose(self, frame_or_series): # round-trip preserved tm.assert_equal(np.transpose(np.transpose(obj)), obj) - msg = r"(the 'axes' parameter is not supported|axes don't match array)" + msg = "the 'axes' parameter is not supported" with pytest.raises(ValueError, match=msg): np.transpose(obj, axes=1) From c216bd911417a127a00a3e069850a1e4d9855a9e Mon Sep 17 00:00:00 2001 From: Irv Lustig Date: Wed, 5 May 2021 11:15:46 -0400 Subject: [PATCH 9/9] create type for fillna arguments --- pandas/_typing.py | 7 +++++++ pandas/core/arrays/base.py | 3 ++- pandas/core/frame.py | 15 ++++++++------- pandas/core/series.py | 15 ++++++++------- 4 files changed, 25 insertions(+), 15 deletions(-) diff --git a/pandas/_typing.py b/pandas/_typing.py index a58dc0dba1bf1..1e1fffdd60676 100644 --- a/pandas/_typing.py +++ b/pandas/_typing.py @@ -37,6 +37,7 @@ # https://mypy.readthedocs.io/en/latest/common_issues.html#import-cycles if TYPE_CHECKING: from typing import ( + Literal, TypedDict, final, ) @@ -189,6 +190,12 @@ str, int, Sequence[Union[str, int]], Mapping[Hashable, Union[str, int]] ] +# Arguments for fillna() +if TYPE_CHECKING: + FillnaOptions = Literal["backfill", "bfill", "ffill", "pad"] +else: + FillnaOptions = str + # internals Manager = Union[ "ArrayManager", "SingleArrayManager", "BlockManager", "SingleBlockManager" diff --git a/pandas/core/arrays/base.py b/pandas/core/arrays/base.py index 5710775f6c89a..16d42e4a51927 100644 --- a/pandas/core/arrays/base.py +++ b/pandas/core/arrays/base.py @@ -25,6 +25,7 @@ from pandas._typing import ( ArrayLike, Dtype, + FillnaOptions, PositionalIndexer, Shape, ) @@ -687,7 +688,7 @@ def argmax(self, skipna: bool = True) -> int: def fillna( self, value: object | ArrayLike | None = None, - method: Literal["backfill", "bfill", "ffill", "pad"] | None = None, + method: FillnaOptions | None = None, limit: int | None = None, ): """ diff --git a/pandas/core/frame.py b/pandas/core/frame.py index d36d6c04e94e6..a508b3db2f038 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -54,6 +54,7 @@ CompressionOptions, Dtype, FilePathOrBuffer, + FillnaOptions, FloatFormatType, FormattersType, FrameOrSeriesUnion, @@ -5015,7 +5016,7 @@ def rename( def fillna( self, value=..., - method: Literal["backfill", "bfill", "ffill", "pad"] | None = ..., + method: FillnaOptions | None = ..., axis: Axis | None = ..., inplace: Literal[False] = ..., limit=..., @@ -5027,7 +5028,7 @@ def fillna( def fillna( self, value, - method: Literal["backfill", "bfill", "ffill", "pad"] | None, + method: FillnaOptions | None, axis: Axis | None, inplace: Literal[True], limit=..., @@ -5060,7 +5061,7 @@ def fillna( def fillna( self, *, - method: Literal["backfill", "bfill", "ffill", "pad"] | None, + method: FillnaOptions | None, inplace: Literal[True], limit=..., downcast=..., @@ -5082,7 +5083,7 @@ def fillna( def fillna( self, *, - method: Literal["backfill", "bfill", "ffill", "pad"] | None, + method: FillnaOptions | None, axis: Axis | None, inplace: Literal[True], limit=..., @@ -5106,7 +5107,7 @@ def fillna( def fillna( self, value, - method: Literal["backfill", "bfill", "ffill", "pad"] | None, + method: FillnaOptions | None, *, inplace: Literal[True], limit=..., @@ -5118,7 +5119,7 @@ def fillna( def fillna( self, value=..., - method: Literal["backfill", "bfill", "ffill", "pad"] | None = ..., + method: FillnaOptions | None = ..., axis: Axis | None = ..., inplace: bool = ..., limit=..., @@ -5130,7 +5131,7 @@ def fillna( def fillna( self, value: object | ArrayLike | None = None, - method: Literal["backfill", "bfill", "ffill", "pad"] | None = None, + method: FillnaOptions | None = None, axis: Axis | None = None, inplace: bool = False, limit=None, diff --git a/pandas/core/series.py b/pandas/core/series.py index b1e57a909908e..c8e9898f9462a 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -38,6 +38,7 @@ Axis, Dtype, DtypeObj, + FillnaOptions, FrameOrSeriesUnion, IndexKeyFunc, NpDtype, @@ -4594,7 +4595,7 @@ def drop( def fillna( self, value=..., - method: Literal["backfill", "bfill", "ffill", "pad"] | None = ..., + method: FillnaOptions | None = ..., axis: Axis | None = ..., inplace: Literal[False] = ..., limit=..., @@ -4606,7 +4607,7 @@ def fillna( def fillna( self, value, - method: Literal["backfill", "bfill", "ffill", "pad"] | None, + method: FillnaOptions | None, axis: Axis | None, inplace: Literal[True], limit=..., @@ -4639,7 +4640,7 @@ def fillna( def fillna( self, *, - method: Literal["backfill", "bfill", "ffill", "pad"] | None, + method: FillnaOptions | None, inplace: Literal[True], limit=..., downcast=..., @@ -4661,7 +4662,7 @@ def fillna( def fillna( self, *, - method: Literal["backfill", "bfill", "ffill", "pad"] | None, + method: FillnaOptions | None, axis: Axis | None, inplace: Literal[True], limit=..., @@ -4685,7 +4686,7 @@ def fillna( def fillna( self, value, - method: Literal["backfill", "bfill", "ffill", "pad"] | None, + method: FillnaOptions | None, *, inplace: Literal[True], limit=..., @@ -4697,7 +4698,7 @@ def fillna( def fillna( self, value=..., - method: Literal["backfill", "bfill", "ffill", "pad"] | None = ..., + method: FillnaOptions | None = ..., axis: Axis | None = ..., inplace: bool = ..., limit=..., @@ -4710,7 +4711,7 @@ def fillna( def fillna( self, value: object | ArrayLike | None = None, - method: Literal["backfill", "bfill", "ffill", "pad"] | None = None, + method: FillnaOptions | None = None, axis=None, inplace=False, limit=None,