Skip to content

Commit e5ce0f9

Browse files
authored
Simplify and fix overloads for methods with inplace parameter (#1105)
The return value of these methods varies on the `inplace` argument.
1 parent 2986c87 commit e5ce0f9

File tree

4 files changed

+193
-284
lines changed

4 files changed

+193
-284
lines changed

pandas-stubs/core/frame.pyi

+49-110
Original file line numberDiff line numberDiff line change
@@ -779,19 +779,6 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
779779
errors: IgnoreRaise = ...,
780780
) -> Self: ...
781781
@overload
782-
def rename(
783-
self,
784-
mapper: Renamer | None = ...,
785-
*,
786-
index: Renamer | None = ...,
787-
columns: Renamer | None = ...,
788-
axis: Axis | None = ...,
789-
copy: bool = ...,
790-
inplace: bool = ...,
791-
level: Level | None = ...,
792-
errors: IgnoreRaise = ...,
793-
) -> Self | None: ...
794-
@overload
795782
def fillna(
796783
self,
797784
value: Scalar | NAType | dict | Series | DataFrame | None = ...,
@@ -812,25 +799,15 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
812799
inplace: Literal[False] = ...,
813800
) -> Self: ...
814801
@overload
815-
def fillna(
816-
self,
817-
value: Scalar | NAType | dict | Series | DataFrame | None = ...,
818-
*,
819-
axis: Axis | None = ...,
820-
inplace: _bool | None = ...,
821-
limit: int = ...,
822-
downcast: dict | None = ...,
823-
) -> Self | None: ...
824-
@overload
825802
def replace(
826803
self,
827804
to_replace=...,
828805
value: Scalar | NAType | Sequence | Mapping | Pattern | None = ...,
829806
*,
807+
inplace: Literal[True],
830808
limit: int | None = ...,
831809
regex=...,
832810
method: ReplaceMethod = ...,
833-
inplace: Literal[True],
834811
) -> None: ...
835812
@overload
836813
def replace(
@@ -843,17 +820,6 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
843820
regex=...,
844821
method: ReplaceMethod = ...,
845822
) -> Self: ...
846-
@overload
847-
def replace(
848-
self,
849-
to_replace=...,
850-
value: Scalar | NAType | Sequence | Mapping | Pattern | None = ...,
851-
*,
852-
inplace: _bool | None = ...,
853-
limit: int | None = ...,
854-
regex=...,
855-
method: ReplaceMethod = ...,
856-
) -> Self | None: ...
857823
def shift(
858824
self,
859825
periods: int = ...,
@@ -919,18 +885,6 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
919885
allow_duplicates: _bool = ...,
920886
names: Hashable | Sequence[Hashable] = ...,
921887
) -> Self: ...
922-
@overload
923-
def reset_index(
924-
self,
925-
level: Level | Sequence[Level] = ...,
926-
*,
927-
drop: _bool = ...,
928-
inplace: _bool | None = ...,
929-
col_level: int | _str = ...,
930-
col_fill: Hashable = ...,
931-
allow_duplicates: _bool = ...,
932-
names: Hashable | Sequence[Hashable] = ...,
933-
) -> Self | None: ...
934888
def isna(self) -> Self: ...
935889
def isnull(self) -> Self: ...
936890
def notna(self) -> Self: ...
@@ -958,17 +912,6 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
958912
ignore_index: _bool = ...,
959913
) -> Self: ...
960914
@overload
961-
def dropna(
962-
self,
963-
*,
964-
axis: Axis = ...,
965-
how: Literal["any", "all"] = ...,
966-
thresh: int | None = ...,
967-
subset: ListLikeU | Scalar | None = ...,
968-
inplace: _bool | None = ...,
969-
ignore_index: _bool = ...,
970-
) -> Self | None: ...
971-
@overload
972915
def drop_duplicates(
973916
self,
974917
subset: Hashable | Iterable[Hashable] | None = ...,
@@ -986,15 +929,6 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
986929
inplace: Literal[False] = ...,
987930
ignore_index: _bool = ...,
988931
) -> Self: ...
989-
@overload
990-
def drop_duplicates(
991-
self,
992-
subset: Hashable | Iterable[Hashable] | None = ...,
993-
*,
994-
keep: NaPosition | _bool = ...,
995-
inplace: _bool = ...,
996-
ignore_index: _bool = ...,
997-
) -> Self | None: ...
998932
def duplicated(
999933
self,
1000934
subset: Hashable | Iterable[Hashable] | None = ...,
@@ -1027,19 +961,6 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
1027961
key: Callable | None = ...,
1028962
) -> Self: ...
1029963
@overload
1030-
def sort_values(
1031-
self,
1032-
by: _str | Sequence[_str],
1033-
*,
1034-
axis: Axis = ...,
1035-
ascending: _bool | Sequence[_bool] = ...,
1036-
inplace: _bool | None = ...,
1037-
kind: SortKind = ...,
1038-
na_position: NaPosition = ...,
1039-
ignore_index: _bool = ...,
1040-
key: Callable | None = ...,
1041-
) -> Self | None: ...
1042-
@overload
1043964
def sort_index(
1044965
self,
1045966
*,
@@ -1068,20 +989,6 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
1068989
key: Callable | None = ...,
1069990
) -> Self: ...
1070991
@overload
1071-
def sort_index(
1072-
self,
1073-
*,
1074-
axis: Axis = ...,
1075-
level: Level | list[int] | list[_str] | None = ...,
1076-
ascending: _bool | Sequence[_bool] = ...,
1077-
inplace: _bool | None = ...,
1078-
kind: SortKind = ...,
1079-
na_position: NaPosition = ...,
1080-
sort_remaining: _bool = ...,
1081-
ignore_index: _bool = ...,
1082-
key: Callable | None = ...,
1083-
) -> Self | None: ...
1084-
@overload
1085992
def value_counts(
1086993
self,
1087994
subset: Sequence[Hashable] | None = ...,
@@ -1824,13 +1731,24 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
18241731
limit_area: Literal["inside", "outside"] | None = ...,
18251732
downcast: dict | None = ...,
18261733
) -> Self: ...
1734+
@overload
18271735
def clip(
18281736
self,
18291737
lower: float | AnyArrayLike | None = ...,
18301738
upper: float | AnyArrayLike | None = ...,
18311739
*,
18321740
axis: Axis | None = ...,
1833-
inplace: _bool = ...,
1741+
inplace: Literal[True],
1742+
**kwargs,
1743+
) -> None: ...
1744+
@overload
1745+
def clip(
1746+
self,
1747+
lower: float | AnyArrayLike | None = ...,
1748+
upper: float | AnyArrayLike | None = ...,
1749+
*,
1750+
axis: Axis | None = ...,
1751+
inplace: Literal[False] = ...,
18341752
**kwargs,
18351753
) -> Self: ...
18361754
def copy(self, deep: _bool = ...) -> Self: ...
@@ -1963,19 +1881,6 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
19631881
inplace: Literal[False] = ...,
19641882
**kwargs,
19651883
) -> Self: ...
1966-
@overload
1967-
def interpolate(
1968-
self,
1969-
method: InterpolateOptions = ...,
1970-
*,
1971-
axis: Axis = ...,
1972-
limit: int | None = ...,
1973-
inplace: _bool | None = ...,
1974-
limit_direction: Literal["forward", "backward", "both"] = ...,
1975-
limit_area: Literal["inside", "outside"] | None = ...,
1976-
downcast: Literal["infer"] | None = ...,
1977-
**kwargs,
1978-
) -> Self | None: ...
19791884
def keys(self) -> Index: ...
19801885
def kurt(
19811886
self,
@@ -1997,6 +1902,7 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
19971902
def last_valid_index(self) -> Scalar: ...
19981903
def le(self, other, axis: Axis = ..., level: Level | None = ...) -> Self: ...
19991904
def lt(self, other, axis: Axis = ..., level: Level | None = ...) -> Self: ...
1905+
@overload
20001906
def mask(
20011907
self,
20021908
cond: (
@@ -2008,7 +1914,23 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
20081914
),
20091915
other: Scalar | Series[S1] | DataFrame | Callable | NAType | None = ...,
20101916
*,
2011-
inplace: _bool = ...,
1917+
inplace: Literal[True],
1918+
axis: Axis | None = ...,
1919+
level: Level | None = ...,
1920+
) -> None: ...
1921+
@overload
1922+
def mask(
1923+
self,
1924+
cond: (
1925+
Series
1926+
| DataFrame
1927+
| np.ndarray
1928+
| Callable[[DataFrame], DataFrame]
1929+
| Callable[[Any], _bool]
1930+
),
1931+
other: Scalar | Series[S1] | DataFrame | Callable | NAType | None = ...,
1932+
*,
1933+
inplace: Literal[False] = ...,
20121934
axis: Axis | None = ...,
20131935
level: Level | None = ...,
20141936
) -> Self: ...
@@ -2470,6 +2392,7 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
24702392
numeric_only: _bool = ...,
24712393
**kwargs,
24722394
) -> Series: ...
2395+
@overload
24732396
def where(
24742397
self,
24752398
cond: (
@@ -2481,7 +2404,23 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
24812404
),
24822405
other=...,
24832406
*,
2484-
inplace: _bool = ...,
2407+
inplace: Literal[True],
2408+
axis: Axis | None = ...,
2409+
level: Level | None = ...,
2410+
) -> None: ...
2411+
@overload
2412+
def where(
2413+
self,
2414+
cond: (
2415+
Series
2416+
| DataFrame
2417+
| np.ndarray
2418+
| Callable[[DataFrame], DataFrame]
2419+
| Callable[[Any], _bool]
2420+
),
2421+
other=...,
2422+
*,
2423+
inplace: Literal[False] = ...,
24852424
axis: Axis | None = ...,
24862425
level: Level | None = ...,
24872426
) -> Self: ...

0 commit comments

Comments
 (0)