Skip to content

Commit 73d5501

Browse files
devesh-2002Dr-Irv
andauthored
Fixed Index.rename() and added test (#936)
* Fixed Index.rename() and added test * Update tests/test_indexes.py Co-authored-by: Irv Lustig <[email protected]> * Update tests/test_indexes.py Co-authored-by: Irv Lustig <[email protected]> * Ran precommit --------- Co-authored-by: Irv Lustig <[email protected]>
1 parent 7ee3df6 commit 73d5501

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

Diff for: pandas-stubs/core/indexes/base.pyi

+1-1
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ class Index(IndexOpsMixin[S1]):
292292
@names.setter
293293
def names(self, names: list[_str]): ...
294294
def set_names(self, names, *, level=..., inplace: bool = ...): ...
295-
def rename(self, name, inplace: bool = ...): ...
295+
def rename(self, name, inplace: bool = ...) -> Self: ...
296296
@property
297297
def nlevels(self) -> int: ...
298298
def sortlevel(self, level=..., ascending: bool = ..., sort_remaining=...): ...

Diff for: tests/test_indexes.py

+6
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,12 @@ def test_str_split() -> None:
113113
check(assert_type(ind.str.split("-", expand=True), pd.MultiIndex), pd.MultiIndex)
114114

115115

116+
def test_index_rename() -> None:
117+
ind = pd.Index([1, 2, 3], name="foo")
118+
ind2 = ind.rename("goo")
119+
check(assert_type(ind2, "pd.Index[int]"), pd.Index, np.integer)
120+
121+
116122
def test_index_dropna():
117123
idx = pd.Index([1, 2])
118124

0 commit comments

Comments
 (0)