Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GhH804 index names typehint #1031

Closed
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
GH804 Index names typing
loicdiridollou committed Nov 13, 2024

Verified

This commit was signed with the committer’s verified signature.
Nothing4You Richard Schwab
commit 21a7794ae86767bf0051f9aea6dcea8c124c06d1
5 changes: 3 additions & 2 deletions pandas-stubs/core/indexes/base.pyi
Original file line number Diff line number Diff line change
@@ -49,6 +49,7 @@ from pandas._typing import (
Label,
Level,
NaPosition,
SequenceNotStr,
TimedeltaDtypeArg,
TimestampDtypeArg,
np_ndarray_anyint,
@@ -288,9 +289,9 @@ class Index(IndexOpsMixin[S1]):
@name.setter
def name(self, value) -> None: ...
@property
def names(self) -> list[_str]: ...
def names(self) -> SequenceNotStr: ...
@names.setter
def names(self, names: list[_str]): ...
def names(self, names: SequenceNotStr): ...
def set_names(self, names, *, level=..., inplace: bool = ...): ...
@overload
def rename(self, name, inplace: Literal[False] = False) -> Self: ...
11 changes: 11 additions & 0 deletions tests/test_indexes.py
Original file line number Diff line number Diff line change
@@ -1160,3 +1160,14 @@ def test_value_counts() -> None:
pd.Series,
float,
)


def test_index_naming() -> None:
"""Test that we can set the names of an index as a hashable."""
df = pd.DataFrame({"a": ["a", "b", "c"], "i": [10, 11, 12]})

df.index.names = ["idx"]

df.index.names = ("idx2",)
df.index.names = [None]
df.index.names = (None,)