From 30a68ced906d14b98921b89a28012d4ae86e58bb Mon Sep 17 00:00:00 2001 From: Kevin Klein Date: Tue, 18 Apr 2023 13:25:00 +0000 Subject: [PATCH 1/4] Add literal type hint. --- pandas/core/indexes/base.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index c13ce8079b669..e399241afbf81 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -208,6 +208,7 @@ _index_shared_docs: dict[str, str] = {} str_t = str +IndexMethod = Literal["pad", "ffill", "backfill", "bfill", "nearest"] _dtype_obj = np.dtype("object") @@ -3742,7 +3743,7 @@ def get_loc(self, key): def get_indexer( self, target, - method: str_t | None = None, + method: IndexMethod | None = None, limit: int | None = None, tolerance=None, ) -> npt.NDArray[np.intp]: @@ -4197,7 +4198,7 @@ def _validate_can_reindex(self, indexer: np.ndarray) -> None: def reindex( self, target, - method=None, + method: IndexMethod | None = None, level=None, limit: int | None = None, tolerance: float | None = None, From 52f163dcd1bab923858110e8a613478bc4805bba Mon Sep 17 00:00:00 2001 From: Kevin Klein Date: Tue, 18 Apr 2023 14:24:27 +0000 Subject: [PATCH 2/4] Move type variable to _typing.py. --- pandas/_typing.py | 2 ++ pandas/core/indexes/base.py | 3 +-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/pandas/_typing.py b/pandas/_typing.py index de02a549856ab..41fd64fe04547 100644 --- a/pandas/_typing.py +++ b/pandas/_typing.py @@ -390,3 +390,5 @@ def closed(self) -> bool: ] AlignJoin = Literal["outer", "inner", "left", "right"] DtypeBackend = Literal["pyarrow", "numpy_nullable"] + +IndexMethod = Literal["pad", "ffill", "backfill", "bfill", "nearest"] diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index e399241afbf81..60f76e7862892 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -53,6 +53,7 @@ F, IgnoreRaise, IndexLabel, + IndexMethod, JoinHow, Level, Self, @@ -208,8 +209,6 @@ _index_shared_docs: dict[str, str] = {} str_t = str -IndexMethod = Literal["pad", "ffill", "backfill", "bfill", "nearest"] - _dtype_obj = np.dtype("object") _masked_engines = { From d378afc10a899c8ad2fd4c2084ec8a15bd013fca Mon Sep 17 00:00:00 2001 From: kklein Date: Sat, 6 May 2023 06:35:12 +0200 Subject: [PATCH 3/4] Use existing type alias. --- pandas/_typing.py | 2 -- pandas/core/indexes/base.py | 6 +++--- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/pandas/_typing.py b/pandas/_typing.py index b0ebec72b8f03..da26b251e8ed4 100644 --- a/pandas/_typing.py +++ b/pandas/_typing.py @@ -419,8 +419,6 @@ def closed(self) -> bool: AlignJoin = Literal["outer", "inner", "left", "right"] DtypeBackend = Literal["pyarrow", "numpy_nullable"] -IndexMethod = Literal["pad", "ffill", "backfill", "bfill", "nearest"] - TimeUnit = Literal["s", "ms", "us", "ns"] OpenFileErrors = Literal[ "strict", diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index 0ab616db6dd91..7a52630296c27 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -53,10 +53,10 @@ F, IgnoreRaise, IndexLabel, - IndexMethod, JoinHow, Level, NaPosition, + ReindexMethod, Self, Shape, npt, @@ -3746,7 +3746,7 @@ def get_loc(self, key): def get_indexer( self, target, - method: IndexMethod | None = None, + method: ReindexMethod | None = None, limit: int | None = None, tolerance=None, ) -> npt.NDArray[np.intp]: @@ -4199,7 +4199,7 @@ def _validate_can_reindex(self, indexer: np.ndarray) -> None: def reindex( self, target, - method: IndexMethod | None = None, + method: ReindexMethod | None = None, level=None, limit: int | None = None, tolerance: float | None = None, From 10c02c4c32f55f66ebfb11fc09482ead749c75db Mon Sep 17 00:00:00 2001 From: kklein Date: Sat, 6 May 2023 06:55:05 +0200 Subject: [PATCH 4/4] EOF --- pandas/_typing.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pandas/_typing.py b/pandas/_typing.py index da26b251e8ed4..9d4acbe76ba15 100644 --- a/pandas/_typing.py +++ b/pandas/_typing.py @@ -444,4 +444,3 @@ def closed(self) -> bool: # to_stata ToStataByteorder = Literal[">", "<", "little", "big"] -