Skip to content

Commit 08b3e11

Browse files
authored
Simplify and fix overloads for methods with inplace parameter
The return value of these methods varies on the `inplace` argument.
1 parent 583d198 commit 08b3e11

File tree

3 files changed

+192
-283
lines changed

3 files changed

+192
-283
lines changed

pandas-stubs/core/frame.pyi

Lines changed: 49 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -760,19 +760,6 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
760760
errors: IgnoreRaise = ...,
761761
) -> Self: ...
762762
@overload
763-
def rename(
764-
self,
765-
mapper: Renamer | None = ...,
766-
*,
767-
index: Renamer | None = ...,
768-
columns: Renamer | None = ...,
769-
axis: Axis | None = ...,
770-
copy: bool = ...,
771-
inplace: bool = ...,
772-
level: Level | None = ...,
773-
errors: IgnoreRaise = ...,
774-
) -> Self | None: ...
775-
@overload
776763
def fillna(
777764
self,
778765
value: Scalar | NAType | dict | Series | DataFrame | None = ...,
@@ -793,25 +780,15 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
793780
inplace: Literal[False] = ...,
794781
) -> Self: ...
795782
@overload
796-
def fillna(
797-
self,
798-
value: Scalar | NAType | dict | Series | DataFrame | None = ...,
799-
*,
800-
axis: Axis | None = ...,
801-
inplace: _bool | None = ...,
802-
limit: int = ...,
803-
downcast: dict | None = ...,
804-
) -> Self | None: ...
805-
@overload
806783
def replace(
807784
self,
808785
to_replace=...,
809786
value: Scalar | NAType | Sequence | Mapping | Pattern | None = ...,
810787
*,
788+
inplace: Literal[True],
811789
limit: int | None = ...,
812790
regex=...,
813791
method: ReplaceMethod = ...,
814-
inplace: Literal[True],
815792
) -> None: ...
816793
@overload
817794
def replace(
@@ -824,17 +801,6 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
824801
regex=...,
825802
method: ReplaceMethod = ...,
826803
) -> Self: ...
827-
@overload
828-
def replace(
829-
self,
830-
to_replace=...,
831-
value: Scalar | NAType | Sequence | Mapping | Pattern | None = ...,
832-
*,
833-
inplace: _bool | None = ...,
834-
limit: int | None = ...,
835-
regex=...,
836-
method: ReplaceMethod = ...,
837-
) -> Self | None: ...
838804
def shift(
839805
self,
840806
periods: int = ...,
@@ -890,18 +856,6 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
890856
allow_duplicates: _bool = ...,
891857
names: Hashable | list[HashableT] = ...,
892858
) -> Self: ...
893-
@overload
894-
def reset_index(
895-
self,
896-
level: Level | Sequence[Level] = ...,
897-
*,
898-
drop: _bool = ...,
899-
inplace: _bool | None = ...,
900-
col_level: int | _str = ...,
901-
col_fill: Hashable = ...,
902-
allow_duplicates: _bool = ...,
903-
names: Hashable | list[HashableT] = ...,
904-
) -> Self | None: ...
905859
def isna(self) -> Self: ...
906860
def isnull(self) -> Self: ...
907861
def notna(self) -> Self: ...
@@ -929,17 +883,6 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
929883
ignore_index: _bool = ...,
930884
) -> Self: ...
931885
@overload
932-
def dropna(
933-
self,
934-
*,
935-
axis: Axis = ...,
936-
how: Literal["any", "all"] = ...,
937-
thresh: int | None = ...,
938-
subset: ListLikeU | Scalar | None = ...,
939-
inplace: _bool | None = ...,
940-
ignore_index: _bool = ...,
941-
) -> Self | None: ...
942-
@overload
943886
def drop_duplicates(
944887
self,
945888
subset: Hashable | Iterable[Hashable] | None = ...,
@@ -957,15 +900,6 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
957900
inplace: Literal[False] = ...,
958901
ignore_index: _bool = ...,
959902
) -> Self: ...
960-
@overload
961-
def drop_duplicates(
962-
self,
963-
subset: Hashable | Iterable[Hashable] | None = ...,
964-
*,
965-
keep: NaPosition | _bool = ...,
966-
inplace: _bool = ...,
967-
ignore_index: _bool = ...,
968-
) -> Self | None: ...
969903
def duplicated(
970904
self,
971905
subset: Hashable | Iterable[Hashable] | None = ...,
@@ -998,19 +932,6 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
998932
key: Callable | None = ...,
999933
) -> Self: ...
1000934
@overload
1001-
def sort_values(
1002-
self,
1003-
by: _str | Sequence[_str],
1004-
*,
1005-
axis: Axis = ...,
1006-
ascending: _bool | Sequence[_bool] = ...,
1007-
inplace: _bool | None = ...,
1008-
kind: SortKind = ...,
1009-
na_position: NaPosition = ...,
1010-
ignore_index: _bool = ...,
1011-
key: Callable | None = ...,
1012-
) -> Self | None: ...
1013-
@overload
1014935
def sort_index(
1015936
self,
1016937
*,
@@ -1039,20 +960,6 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
1039960
key: Callable | None = ...,
1040961
) -> Self: ...
1041962
@overload
1042-
def sort_index(
1043-
self,
1044-
*,
1045-
axis: Axis = ...,
1046-
level: Level | list[int] | list[_str] | None = ...,
1047-
ascending: _bool | Sequence[_bool] = ...,
1048-
inplace: _bool | None = ...,
1049-
kind: SortKind = ...,
1050-
na_position: NaPosition = ...,
1051-
sort_remaining: _bool = ...,
1052-
ignore_index: _bool = ...,
1053-
key: Callable | None = ...,
1054-
) -> Self | None: ...
1055-
@overload
1056963
def value_counts(
1057964
self,
1058965
subset: Sequence[Hashable] | None = ...,
@@ -1795,13 +1702,24 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
17951702
limit_area: Literal["inside", "outside"] | None = ...,
17961703
downcast: dict | None = ...,
17971704
) -> Self: ...
1705+
@overload
17981706
def clip(
17991707
self,
18001708
lower: float | AnyArrayLike | None = ...,
18011709
upper: float | AnyArrayLike | None = ...,
18021710
*,
18031711
axis: Axis | None = ...,
1804-
inplace: _bool = ...,
1712+
inplace: Literal[True],
1713+
**kwargs,
1714+
) -> None: ...
1715+
@overload
1716+
def clip(
1717+
self,
1718+
lower: float | AnyArrayLike | None = ...,
1719+
upper: float | AnyArrayLike | None = ...,
1720+
*,
1721+
axis: Axis | None = ...,
1722+
inplace: Literal[False] = ...,
18051723
**kwargs,
18061724
) -> Self: ...
18071725
def copy(self, deep: _bool = ...) -> Self: ...
@@ -1934,19 +1852,6 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
19341852
inplace: Literal[False] = ...,
19351853
**kwargs,
19361854
) -> Self: ...
1937-
@overload
1938-
def interpolate(
1939-
self,
1940-
method: InterpolateOptions = ...,
1941-
*,
1942-
axis: Axis = ...,
1943-
limit: int | None = ...,
1944-
inplace: _bool | None = ...,
1945-
limit_direction: Literal["forward", "backward", "both"] = ...,
1946-
limit_area: Literal["inside", "outside"] | None = ...,
1947-
downcast: Literal["infer"] | None = ...,
1948-
**kwargs,
1949-
) -> Self | None: ...
19501855
def keys(self) -> Index: ...
19511856
def kurt(
19521857
self,
@@ -1968,6 +1873,7 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
19681873
def last_valid_index(self) -> Scalar: ...
19691874
def le(self, other, axis: Axis = ..., level: Level | None = ...) -> Self: ...
19701875
def lt(self, other, axis: Axis = ..., level: Level | None = ...) -> Self: ...
1876+
@overload
19711877
def mask(
19721878
self,
19731879
cond: (
@@ -1979,7 +1885,23 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
19791885
),
19801886
other: Scalar | Series[S1] | DataFrame | Callable | NAType | None = ...,
19811887
*,
1982-
inplace: _bool = ...,
1888+
inplace: Literal[True],
1889+
axis: Axis | None = ...,
1890+
level: Level | None = ...,
1891+
) -> None: ...
1892+
@overload
1893+
def mask(
1894+
self,
1895+
cond: (
1896+
Series
1897+
| DataFrame
1898+
| np.ndarray
1899+
| Callable[[DataFrame], DataFrame]
1900+
| Callable[[Any], _bool]
1901+
),
1902+
other: Scalar | Series[S1] | DataFrame | Callable | NAType | None = ...,
1903+
*,
1904+
inplace: Literal[False] = ...,
19831905
axis: Axis | None = ...,
19841906
level: Level | None = ...,
19851907
) -> Self: ...
@@ -2441,6 +2363,7 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
24412363
numeric_only: _bool = ...,
24422364
**kwargs,
24432365
) -> Series: ...
2366+
@overload
24442367
def where(
24452368
self,
24462369
cond: (
@@ -2452,7 +2375,23 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
24522375
),
24532376
other=...,
24542377
*,
2455-
inplace: _bool = ...,
2378+
inplace: Literal[True],
2379+
axis: Axis | None = ...,
2380+
level: Level | None = ...,
2381+
) -> None: ...
2382+
@overload
2383+
def where(
2384+
self,
2385+
cond: (
2386+
Series
2387+
| DataFrame
2388+
| np.ndarray
2389+
| Callable[[DataFrame], DataFrame]
2390+
| Callable[[Any], _bool]
2391+
),
2392+
other=...,
2393+
*,
2394+
inplace: Literal[False] = ...,
24562395
axis: Axis | None = ...,
24572396
level: Level | None = ...,
24582397
) -> Self: ...

0 commit comments

Comments
 (0)