From 8a2029369506cb4cde49fa2c94604df5d361bece Mon Sep 17 00:00:00 2001 From: mattkeanny Date: Tue, 18 Apr 2023 14:48:54 +0000 Subject: [PATCH 1/2] Typing: Narrow down types of argument keep for nsmallest and nlargest --- pandas/core/series.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/series.py b/pandas/core/series.py index adb16c2f2dd55..96b120f6f3e7f 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -3897,7 +3897,7 @@ def nlargest( """ return selectn.SelectNSeries(self, n=n, keep=keep).nlargest() - def nsmallest(self, n: int = 5, keep: str = "first") -> Series: + def nsmallest(self, n: int = 5, keep: Literal["first", "last", "all"] = "first") -> Series: """ Return the smallest `n` elements. From 5635f3dfcc63b622a40eda9e362103651d656173 Mon Sep 17 00:00:00 2001 From: mattkeanny Date: Thu, 20 Apr 2023 17:48:37 +0000 Subject: [PATCH 2/2] fixed formatting with black --- pandas/core/series.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pandas/core/series.py b/pandas/core/series.py index 96b120f6f3e7f..8757d5f2df5b1 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -3897,7 +3897,9 @@ def nlargest( """ return selectn.SelectNSeries(self, n=n, keep=keep).nlargest() - def nsmallest(self, n: int = 5, keep: Literal["first", "last", "all"] = "first") -> Series: + def nsmallest( + self, n: int = 5, keep: Literal["first", "last", "all"] = "first" + ) -> Series: """ Return the smallest `n` elements.