Skip to content

Commit 348ddf9

Browse files
committed
precommit passes
1 parent a09552e commit 348ddf9

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

pandas/core/methods/selectn.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from typing import (
1212
TYPE_CHECKING,
1313
Generic,
14+
Literal,
1415
cast,
1516
final,
1617
)
@@ -54,7 +55,9 @@
5455

5556

5657
class SelectN(Generic[NDFrameT]):
57-
def __init__(self, obj: NDFrameT, n: int, keep: str) -> None:
58+
def __init__(
59+
self, obj: NDFrameT, n: int, keep: Literal["first", "last", "all"]
60+
) -> None:
5861
self.obj = obj
5962
self.n = n
6063
self.keep = keep
@@ -111,9 +114,9 @@ def compute(self, method: str) -> Series:
111114
if n <= 0:
112115
return self.obj[[]]
113116

114-
# Save index and reset to default index to avoid performance impact
117+
# Save index and reset to default index to avoid performance impact
115118
# from when index contains duplicates
116-
original_index = self.obj.index
119+
original_index: Index = self.obj.index
117120
cur_series = self.obj.reset_index(drop=True)
118121

119122
dropped = cur_series.dropna()
@@ -122,7 +125,9 @@ def compute(self, method: str) -> Series:
122125
# slow method
123126
if n >= len(cur_series):
124127
ascending = method == "nsmallest"
125-
final_series = cur_series.sort_values(ascending=ascending, kind="mergesort").head(n)
128+
final_series = cur_series.sort_values(
129+
ascending=ascending, kind="mergesort"
130+
).head(n)
126131
final_series.index = original_index.take(final_series.index)
127132
return final_series
128133

0 commit comments

Comments
 (0)