Skip to content

Commit

Permalink
GH935 Create overload for pd.Index.rename
Browse files Browse the repository at this point in the history
  • Loading branch information
loicdiridollou committed Oct 8, 2024
1 parent e50358f commit c1cac48
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
5 changes: 4 additions & 1 deletion pandas-stubs/core/indexes/base.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,10 @@ class Index(IndexOpsMixin[S1]):
@names.setter
def names(self, names: list[_str]): ...
def set_names(self, names, *, level=..., inplace: bool = ...): ...
def rename(self, name, inplace: bool = ...) -> Self: ...
@overload
def rename(self, name, inplace: Literal[False] = False) -> Self: ...
@overload
def rename(self, name, inplace: Literal[True]) -> None: ...
@property
def nlevels(self) -> int: ...
def sortlevel(self, level=..., ascending: bool = ..., sort_remaining=...): ...
Expand Down
9 changes: 9 additions & 0 deletions tests/test_indexes.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,20 @@ def test_str_match() -> None:


def test_index_rename() -> None:
"""Test that index rename returns an element of type Index."""
ind = pd.Index([1, 2, 3], name="foo")
ind2 = ind.rename("goo")
check(assert_type(ind2, "pd.Index[int]"), pd.Index, np.integer)


def test_index_rename_inplace() -> None:
"""Test that index rename in-place does not return anything (None)."""
ind = pd.Index([1, 2, 3], name="foo")
ind2 = ind.rename("goo", inplace=True)
check(assert_type(ind2, None), type(None))
assert ind2 is None


def test_index_dropna():
idx = pd.Index([1, 2])

Expand Down

0 comments on commit c1cac48

Please sign in to comment.