Skip to content

Commit 8ca2e37

Browse files
authored
Literal typing for indexer methods (#52729)
* typing for indexer methods * more literal typing for na_position for range * another na_position to be typed * use NaPosition in pandas._typing
1 parent 6fc3da6 commit 8ca2e37

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

pandas/core/indexes/base.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
IndexLabel,
5656
JoinHow,
5757
Level,
58+
NaPosition,
5859
Self,
5960
Shape,
6061
npt,
@@ -1921,7 +1922,7 @@ def sortlevel(
19211922
level=None,
19221923
ascending: bool | list[bool] = True,
19231924
sort_remaining=None,
1924-
na_position: str_t = "first",
1925+
na_position: NaPosition = "first",
19251926
):
19261927
"""
19271928
For internal compatibility with the Index API.
@@ -5573,7 +5574,7 @@ def sort_values(
55735574
self,
55745575
return_indexer: bool = False,
55755576
ascending: bool = True,
5576-
na_position: str_t = "last",
5577+
na_position: NaPosition = "last",
55775578
key: Callable | None = None,
55785579
):
55795580
"""
@@ -6168,7 +6169,7 @@ def groupby(self, values) -> PrettyDict[Hashable, np.ndarray]:
61686169

61696170
return PrettyDict(result)
61706171

6171-
def map(self, mapper, na_action=None):
6172+
def map(self, mapper, na_action: Literal["ignore"] | None = None):
61726173
"""
61736174
Map values using an input mapping or function.
61746175

pandas/core/indexes/range.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
if TYPE_CHECKING:
5151
from pandas._typing import (
5252
Dtype,
53+
NaPosition,
5354
Self,
5455
npt,
5556
)
@@ -493,7 +494,7 @@ def sort_values(
493494
self,
494495
return_indexer: bool = False,
495496
ascending: bool = True,
496-
na_position: str = "last",
497+
na_position: NaPosition = "last",
497498
key: Callable | None = None,
498499
):
499500
if key is not None:

0 commit comments

Comments
 (0)