Skip to content

Commit 21a7794

Browse files
GH804 Index names typing
1 parent 0ab562c commit 21a7794

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

pandas-stubs/core/indexes/base.pyi

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ from pandas._typing import (
4949
Label,
5050
Level,
5151
NaPosition,
52+
SequenceNotStr,
5253
TimedeltaDtypeArg,
5354
TimestampDtypeArg,
5455
np_ndarray_anyint,
@@ -288,9 +289,9 @@ class Index(IndexOpsMixin[S1]):
288289
@name.setter
289290
def name(self, value) -> None: ...
290291
@property
291-
def names(self) -> list[_str]: ...
292+
def names(self) -> SequenceNotStr: ...
292293
@names.setter
293-
def names(self, names: list[_str]): ...
294+
def names(self, names: SequenceNotStr): ...
294295
def set_names(self, names, *, level=..., inplace: bool = ...): ...
295296
@overload
296297
def rename(self, name, inplace: Literal[False] = False) -> Self: ...

tests/test_indexes.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1160,3 +1160,14 @@ def test_value_counts() -> None:
11601160
pd.Series,
11611161
float,
11621162
)
1163+
1164+
1165+
def test_index_naming() -> None:
1166+
"""Test that we can set the names of an index as a hashable."""
1167+
df = pd.DataFrame({"a": ["a", "b", "c"], "i": [10, 11, 12]})
1168+
1169+
df.index.names = ["idx"]
1170+
1171+
df.index.names = ("idx2",)
1172+
df.index.names = [None]
1173+
df.index.names = (None,)

0 commit comments

Comments
 (0)