From 1e962f04669f8e0aa5f80645dd1e1162c5b00128 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torsten=20W=C3=B6rtwein?= Date: Sat, 25 Jun 2022 18:46:46 -0400 Subject: [PATCH 1/3] TYP: misc --- pandas/core/generic.py | 2 +- pandas/core/indexes/multi.py | 7 +++++-- pandas/core/window/expanding.py | 3 ++- pandas/core/window/rolling.py | 5 +++-- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 589ea6e67d926..75f16c8f9eb16 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -6608,7 +6608,7 @@ def replace( inplace: bool_t = False, limit: int | None = None, regex=False, - method=lib.no_default, + method: str | lib.NoDefault = lib.no_default, ): if not ( is_scalar(to_replace) diff --git a/pandas/core/indexes/multi.py b/pandas/core/indexes/multi.py index 15d06ef3bc8e5..4da39318579eb 100644 --- a/pandas/core/indexes/multi.py +++ b/pandas/core/indexes/multi.py @@ -2643,7 +2643,10 @@ def _get_indexer_level_0(self, target) -> npt.NDArray[np.intp]: return ci.get_indexer_for(target) def get_slice_bound( - self, label: Hashable | Sequence[Hashable], side: str, kind=lib.no_default + self, + label: Hashable | Sequence[Hashable], + side: Literal["left", "right"], + kind=lib.no_default, ) -> int: """ For an ordered MultiIndex, compute slice bound @@ -2758,7 +2761,7 @@ def slice_locs( # happens in get_slice_bound method), but it adds meaningful doc. return super().slice_locs(start, end, step) - def _partial_tup_index(self, tup: tuple, side="left"): + def _partial_tup_index(self, tup: tuple, side: Literal["left", "right"] = "left"): if len(tup) > self._lexsort_depth: raise UnsortedIndexError( f"Key length ({len(tup)}) was greater than MultiIndex lexsort depth " diff --git a/pandas/core/window/expanding.py b/pandas/core/window/expanding.py index d1a8b70b34462..dcdcbc0483d59 100644 --- a/pandas/core/window/expanding.py +++ b/pandas/core/window/expanding.py @@ -9,6 +9,7 @@ from pandas._typing import ( Axis, + QuantileInterpolation, WindowingRankType, ) @@ -651,7 +652,7 @@ def kurt(self, numeric_only: bool = False, **kwargs): def quantile( self, quantile: float, - interpolation: str = "linear", + interpolation: QuantileInterpolation = "linear", numeric_only: bool = False, **kwargs, ): diff --git a/pandas/core/window/rolling.py b/pandas/core/window/rolling.py index b45f43adbe952..6e47c46cc7203 100644 --- a/pandas/core/window/rolling.py +++ b/pandas/core/window/rolling.py @@ -29,6 +29,7 @@ ArrayLike, Axis, NDFrameT, + QuantileInterpolation, WindowingRankType, ) from pandas.compat._optional import import_optional_dependency @@ -1658,7 +1659,7 @@ def kurt(self, numeric_only: bool = False, **kwargs): def quantile( self, quantile: float, - interpolation: str = "linear", + interpolation: QuantileInterpolation = "linear", numeric_only: bool = False, **kwargs, ): @@ -2553,7 +2554,7 @@ def kurt(self, numeric_only: bool = False, **kwargs): def quantile( self, quantile: float, - interpolation: str = "linear", + interpolation: QuantileInterpolation = "linear", numeric_only: bool = False, **kwargs, ): From e40e1ac2a7cc450fde8786caf3fc61f20585d9cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torsten=20W=C3=B6rtwein?= Date: Sun, 26 Jun 2022 15:30:40 -0400 Subject: [PATCH 2/3] Update pandas/core/generic.py Co-authored-by: Matthew Roeschke --- pandas/core/generic.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 75f16c8f9eb16..ffffd43e95fc9 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -6608,7 +6608,7 @@ def replace( inplace: bool_t = False, limit: int | None = None, regex=False, - method: str | lib.NoDefault = lib.no_default, + method: Literal["pad", "ffill", "bfill"] | lib.NoDefault = lib.no_default, ): if not ( is_scalar(to_replace) From ca3bf1845501a71e64fa3fae273b24cf9a271259 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torsten=20W=C3=B6rtwein?= Date: Sun, 26 Jun 2022 15:54:07 -0400 Subject: [PATCH 3/3] None errors --- pandas/core/frame.py | 2 +- pandas/core/series.py | 2 +- pandas/core/shared_docs.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index b4a278185b01b..b799b6df84ec4 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -5545,7 +5545,7 @@ def replace( inplace: bool = False, limit=None, regex: bool = False, - method: str | lib.NoDefault = lib.no_default, + method: Literal["pad", "ffill", "bfill"] | lib.NoDefault = lib.no_default, ): return super().replace( to_replace=to_replace, diff --git a/pandas/core/series.py b/pandas/core/series.py index 6ebee74810305..69fbbb2ab5570 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -5204,7 +5204,7 @@ def replace( inplace=False, limit=None, regex=False, - method: str | lib.NoDefault = lib.no_default, + method: Literal["pad", "ffill", "bfill"] | lib.NoDefault = lib.no_default, ): return super().replace( to_replace=to_replace, diff --git a/pandas/core/shared_docs.py b/pandas/core/shared_docs.py index 3a8a95865d10e..09ee254633b22 100644 --- a/pandas/core/shared_docs.py +++ b/pandas/core/shared_docs.py @@ -541,7 +541,7 @@ string. Alternatively, this could be a regular expression or a list, dict, or array of regular expressions in which case `to_replace` must be ``None``. - method : {{'pad', 'ffill', 'bfill', `None`}} + method : {{'pad', 'ffill', 'bfill'}} The method to use when for replacement, when `to_replace` is a scalar, list or tuple and `value` is ``None``.