|
34 | 34 | Type, |
35 | 35 | Union, |
36 | 36 | cast, |
| 37 | + overload, |
37 | 38 | ) |
38 | 39 | import warnings |
39 | 40 |
|
|
155 | 156 | import pandas.plotting |
156 | 157 |
|
157 | 158 | if TYPE_CHECKING: |
| 159 | + from typing import Literal |
| 160 | + |
158 | 161 | from pandas.core.groupby.generic import DataFrameGroupBy |
159 | 162 |
|
160 | 163 | from pandas.io.formats.style import Styler |
@@ -971,9 +974,6 @@ def iterrows(self) -> Iterable[Tuple[Label, Series]]: |
971 | 974 | data : Series |
972 | 975 | The data of the row as a Series. |
973 | 976 |
|
974 | | - it : generator |
975 | | - A generator that iterates over the rows of the frame. |
976 | | -
|
977 | 977 | See Also |
978 | 978 | -------- |
979 | 979 | DataFrame.itertuples : Iterate over DataFrame rows as namedtuples of the values. |
@@ -4706,6 +4706,30 @@ def set_index( |
4706 | 4706 | if not inplace: |
4707 | 4707 | return frame |
4708 | 4708 |
|
| 4709 | + @overload |
| 4710 | + # https://github.com/python/mypy/issues/6580 |
| 4711 | + # Overloaded function signatures 1 and 2 overlap with incompatible return types |
| 4712 | + def reset_index( # type: ignore[misc] |
| 4713 | + self, |
| 4714 | + level: Optional[Union[Hashable, Sequence[Hashable]]] = ..., |
| 4715 | + drop: bool = ..., |
| 4716 | + inplace: Literal[False] = ..., |
| 4717 | + col_level: Hashable = ..., |
| 4718 | + col_fill: Label = ..., |
| 4719 | + ) -> DataFrame: |
| 4720 | + ... |
| 4721 | + |
| 4722 | + @overload |
| 4723 | + def reset_index( |
| 4724 | + self, |
| 4725 | + level: Optional[Union[Hashable, Sequence[Hashable]]] = ..., |
| 4726 | + drop: bool = ..., |
| 4727 | + inplace: Literal[True] = ..., |
| 4728 | + col_level: Hashable = ..., |
| 4729 | + col_fill: Label = ..., |
| 4730 | + ) -> None: |
| 4731 | + ... |
| 4732 | + |
4709 | 4733 | def reset_index( |
4710 | 4734 | self, |
4711 | 4735 | level: Optional[Union[Hashable, Sequence[Hashable]]] = None, |
@@ -7185,8 +7209,6 @@ def explode( |
7185 | 7209 | raise ValueError("columns must be unique") |
7186 | 7210 |
|
7187 | 7211 | df = self.reset_index(drop=True) |
7188 | | - # TODO: use overload to refine return type of reset_index |
7189 | | - assert df is not None # needed for mypy |
7190 | 7212 | result = df[column].explode() |
7191 | 7213 | result = df.drop([column], axis=1).join(result) |
7192 | 7214 | if ignore_index: |
@@ -7256,7 +7278,9 @@ def unstack(self, level=-1, fill_value=None): |
7256 | 7278 | """ |
7257 | 7279 | from pandas.core.reshape.reshape import unstack |
7258 | 7280 |
|
7259 | | - return unstack(self, level, fill_value) |
| 7281 | + result = unstack(self, level, fill_value) |
| 7282 | + |
| 7283 | + return result.__finalize__(self, method="unstack") |
7260 | 7284 |
|
7261 | 7285 | @Appender(_shared_docs["melt"] % dict(caller="df.melt(", other="melt")) |
7262 | 7286 | def melt( |
|
0 commit comments