Skip to content

Commit f6c8b61

Browse files
committed
Simplify and fix overloads for methods with inplace parameter
The return value of these methods varies on the `inplace` argument.
1 parent 4976e11 commit f6c8b61

File tree

4 files changed

+193
-284
lines changed

4 files changed

+193
-284
lines changed

pandas-stubs/core/frame.pyi

Lines changed: 49 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -778,19 +778,6 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
778778
errors: IgnoreRaise = ...,
779779
) -> Self: ...
780780
@overload
781-
def rename(
782-
self,
783-
mapper: Renamer | None = ...,
784-
*,
785-
index: Renamer | None = ...,
786-
columns: Renamer | None = ...,
787-
axis: Axis | None = ...,
788-
copy: bool = ...,
789-
inplace: bool = ...,
790-
level: Level | None = ...,
791-
errors: IgnoreRaise = ...,
792-
) -> Self | None: ...
793-
@overload
794781
def fillna(
795782
self,
796783
value: Scalar | NAType | dict | Series | DataFrame | None = ...,
@@ -811,25 +798,15 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
811798
inplace: Literal[False] = ...,
812799
) -> Self: ...
813800
@overload
814-
def fillna(
815-
self,
816-
value: Scalar | NAType | dict | Series | DataFrame | None = ...,
817-
*,
818-
axis: Axis | None = ...,
819-
inplace: _bool | None = ...,
820-
limit: int = ...,
821-
downcast: dict | None = ...,
822-
) -> Self | None: ...
823-
@overload
824801
def replace(
825802
self,
826803
to_replace=...,
827804
value: Scalar | NAType | Sequence | Mapping | Pattern | None = ...,
828805
*,
806+
inplace: Literal[True],
829807
limit: int | None = ...,
830808
regex=...,
831809
method: ReplaceMethod = ...,
832-
inplace: Literal[True],
833810
) -> None: ...
834811
@overload
835812
def replace(
@@ -842,17 +819,6 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
842819
regex=...,
843820
method: ReplaceMethod = ...,
844821
) -> Self: ...
845-
@overload
846-
def replace(
847-
self,
848-
to_replace=...,
849-
value: Scalar | NAType | Sequence | Mapping | Pattern | None = ...,
850-
*,
851-
inplace: _bool | None = ...,
852-
limit: int | None = ...,
853-
regex=...,
854-
method: ReplaceMethod = ...,
855-
) -> Self | None: ...
856822
def shift(
857823
self,
858824
periods: int = ...,
@@ -918,18 +884,6 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
918884
allow_duplicates: _bool = ...,
919885
names: Hashable | Sequence[Hashable] = ...,
920886
) -> Self: ...
921-
@overload
922-
def reset_index(
923-
self,
924-
level: Level | Sequence[Level] = ...,
925-
*,
926-
drop: _bool = ...,
927-
inplace: _bool | None = ...,
928-
col_level: int | _str = ...,
929-
col_fill: Hashable = ...,
930-
allow_duplicates: _bool = ...,
931-
names: Hashable | Sequence[Hashable] = ...,
932-
) -> Self | None: ...
933887
def isna(self) -> Self: ...
934888
def isnull(self) -> Self: ...
935889
def notna(self) -> Self: ...
@@ -957,17 +911,6 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
957911
ignore_index: _bool = ...,
958912
) -> Self: ...
959913
@overload
960-
def dropna(
961-
self,
962-
*,
963-
axis: Axis = ...,
964-
how: Literal["any", "all"] = ...,
965-
thresh: int | None = ...,
966-
subset: ListLikeU | Scalar | None = ...,
967-
inplace: _bool | None = ...,
968-
ignore_index: _bool = ...,
969-
) -> Self | None: ...
970-
@overload
971914
def drop_duplicates(
972915
self,
973916
subset: Hashable | Iterable[Hashable] | None = ...,
@@ -985,15 +928,6 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
985928
inplace: Literal[False] = ...,
986929
ignore_index: _bool = ...,
987930
) -> Self: ...
988-
@overload
989-
def drop_duplicates(
990-
self,
991-
subset: Hashable | Iterable[Hashable] | None = ...,
992-
*,
993-
keep: NaPosition | _bool = ...,
994-
inplace: _bool = ...,
995-
ignore_index: _bool = ...,
996-
) -> Self | None: ...
997931
def duplicated(
998932
self,
999933
subset: Hashable | Iterable[Hashable] | None = ...,
@@ -1026,19 +960,6 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
1026960
key: Callable | None = ...,
1027961
) -> Self: ...
1028962
@overload
1029-
def sort_values(
1030-
self,
1031-
by: _str | Sequence[_str],
1032-
*,
1033-
axis: Axis = ...,
1034-
ascending: _bool | Sequence[_bool] = ...,
1035-
inplace: _bool | None = ...,
1036-
kind: SortKind = ...,
1037-
na_position: NaPosition = ...,
1038-
ignore_index: _bool = ...,
1039-
key: Callable | None = ...,
1040-
) -> Self | None: ...
1041-
@overload
1042963
def sort_index(
1043964
self,
1044965
*,
@@ -1067,20 +988,6 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
1067988
key: Callable | None = ...,
1068989
) -> Self: ...
1069990
@overload
1070-
def sort_index(
1071-
self,
1072-
*,
1073-
axis: Axis = ...,
1074-
level: Level | list[int] | list[_str] | None = ...,
1075-
ascending: _bool | Sequence[_bool] = ...,
1076-
inplace: _bool | None = ...,
1077-
kind: SortKind = ...,
1078-
na_position: NaPosition = ...,
1079-
sort_remaining: _bool = ...,
1080-
ignore_index: _bool = ...,
1081-
key: Callable | None = ...,
1082-
) -> Self | None: ...
1083-
@overload
1084991
def value_counts(
1085992
self,
1086993
subset: Sequence[Hashable] | None = ...,
@@ -1823,13 +1730,24 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
18231730
limit_area: Literal["inside", "outside"] | None = ...,
18241731
downcast: dict | None = ...,
18251732
) -> Self: ...
1733+
@overload
18261734
def clip(
18271735
self,
18281736
lower: float | AnyArrayLike | None = ...,
18291737
upper: float | AnyArrayLike | None = ...,
18301738
*,
18311739
axis: Axis | None = ...,
1832-
inplace: _bool = ...,
1740+
inplace: Literal[True],
1741+
**kwargs,
1742+
) -> None: ...
1743+
@overload
1744+
def clip(
1745+
self,
1746+
lower: float | AnyArrayLike | None = ...,
1747+
upper: float | AnyArrayLike | None = ...,
1748+
*,
1749+
axis: Axis | None = ...,
1750+
inplace: Literal[False] = ...,
18331751
**kwargs,
18341752
) -> Self: ...
18351753
def copy(self, deep: _bool = ...) -> Self: ...
@@ -1962,19 +1880,6 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
19621880
inplace: Literal[False] = ...,
19631881
**kwargs,
19641882
) -> Self: ...
1965-
@overload
1966-
def interpolate(
1967-
self,
1968-
method: InterpolateOptions = ...,
1969-
*,
1970-
axis: Axis = ...,
1971-
limit: int | None = ...,
1972-
inplace: _bool | None = ...,
1973-
limit_direction: Literal["forward", "backward", "both"] = ...,
1974-
limit_area: Literal["inside", "outside"] | None = ...,
1975-
downcast: Literal["infer"] | None = ...,
1976-
**kwargs,
1977-
) -> Self | None: ...
19781883
def keys(self) -> Index: ...
19791884
def kurt(
19801885
self,
@@ -1996,6 +1901,7 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
19961901
def last_valid_index(self) -> Scalar: ...
19971902
def le(self, other, axis: Axis = ..., level: Level | None = ...) -> Self: ...
19981903
def lt(self, other, axis: Axis = ..., level: Level | None = ...) -> Self: ...
1904+
@overload
19991905
def mask(
20001906
self,
20011907
cond: (
@@ -2007,7 +1913,23 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
20071913
),
20081914
other: Scalar | Series[S1] | DataFrame | Callable | NAType | None = ...,
20091915
*,
2010-
inplace: _bool = ...,
1916+
inplace: Literal[True],
1917+
axis: Axis | None = ...,
1918+
level: Level | None = ...,
1919+
) -> None: ...
1920+
@overload
1921+
def mask(
1922+
self,
1923+
cond: (
1924+
Series
1925+
| DataFrame
1926+
| np.ndarray
1927+
| Callable[[DataFrame], DataFrame]
1928+
| Callable[[Any], _bool]
1929+
),
1930+
other: Scalar | Series[S1] | DataFrame | Callable | NAType | None = ...,
1931+
*,
1932+
inplace: Literal[False] = ...,
20111933
axis: Axis | None = ...,
20121934
level: Level | None = ...,
20131935
) -> Self: ...
@@ -2469,6 +2391,7 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
24692391
numeric_only: _bool = ...,
24702392
**kwargs,
24712393
) -> Series: ...
2394+
@overload
24722395
def where(
24732396
self,
24742397
cond: (
@@ -2480,7 +2403,23 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
24802403
),
24812404
other=...,
24822405
*,
2483-
inplace: _bool = ...,
2406+
inplace: Literal[True],
2407+
axis: Axis | None = ...,
2408+
level: Level | None = ...,
2409+
) -> None: ...
2410+
@overload
2411+
def where(
2412+
self,
2413+
cond: (
2414+
Series
2415+
| DataFrame
2416+
| np.ndarray
2417+
| Callable[[DataFrame], DataFrame]
2418+
| Callable[[Any], _bool]
2419+
),
2420+
other=...,
2421+
*,
2422+
inplace: Literal[False] = ...,
24842423
axis: Axis | None = ...,
24852424
level: Level | None = ...,
24862425
) -> Self: ...

0 commit comments

Comments
 (0)