|
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
|
@@ -4706,6 +4709,30 @@ def set_index(
|
4706 | 4709 | if not inplace:
|
4707 | 4710 | return frame
|
4708 | 4711 |
|
| 4712 | + @overload |
| 4713 | + # https://github.com/python/mypy/issues/6580 |
| 4714 | + # Overloaded function signatures 1 and 2 overlap with incompatible return types |
| 4715 | + def reset_index( # type: ignore[misc] |
| 4716 | + self, |
| 4717 | + level: Optional[Union[Hashable, Sequence[Hashable]]] = ..., |
| 4718 | + drop: bool = ..., |
| 4719 | + inplace: Literal[False] = ..., |
| 4720 | + col_level: Hashable = ..., |
| 4721 | + col_fill: Label = ..., |
| 4722 | + ) -> DataFrame: |
| 4723 | + ... |
| 4724 | + |
| 4725 | + @overload |
| 4726 | + def reset_index( |
| 4727 | + self, |
| 4728 | + level: Optional[Union[Hashable, Sequence[Hashable]]] = ..., |
| 4729 | + drop: bool = ..., |
| 4730 | + inplace: Literal[True] = ..., |
| 4731 | + col_level: Hashable = ..., |
| 4732 | + col_fill: Label = ..., |
| 4733 | + ) -> None: |
| 4734 | + ... |
| 4735 | + |
4709 | 4736 | def reset_index(
|
4710 | 4737 | self,
|
4711 | 4738 | level: Optional[Union[Hashable, Sequence[Hashable]]] = None,
|
@@ -7185,8 +7212,6 @@ def explode(
|
7185 | 7212 | raise ValueError("columns must be unique")
|
7186 | 7213 |
|
7187 | 7214 | 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 | 7215 | result = df[column].explode()
|
7191 | 7216 | result = df.drop([column], axis=1).join(result)
|
7192 | 7217 | if ignore_index:
|
|
0 commit comments