Skip to content

Commit 4487a36

Browse files
committed
correct name annotation for MultiIndex
1 parent f7ae655 commit 4487a36

File tree

2 files changed

+11
-13
lines changed

2 files changed

+11
-13
lines changed

pandas-stubs/core/indexes/multi.pyi

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ from typing import (
99
overload,
1010
)
1111

12+
from _typing import SequenceNotStr
1213
import numpy as np
1314
import pandas as pd
1415
from pandas.core.indexes.base import Index
@@ -24,18 +25,6 @@ from pandas._typing import (
2425
)
2526

2627
class MultiIndex(Index[Any]):
27-
def __new__(
28-
cls,
29-
levels=...,
30-
codes=...,
31-
sortorder=...,
32-
names=...,
33-
dtype=...,
34-
copy=...,
35-
name: Hashable = ...,
36-
verify_integrity: bool = ...,
37-
_set_identity: bool = ...,
38-
) -> Self: ...
3928
def __init__(
4029
self,
4130
levels=...,
@@ -44,7 +33,7 @@ class MultiIndex(Index[Any]):
4433
names=...,
4534
dtype=...,
4635
copy=...,
47-
name: Hashable = ...,
36+
name: SequenceNotStr[Hashable] = ...,
4837
verify_integrity: bool = ...,
4938
_set_identity: bool = ...,
5039
) -> None: ...

tests/test_indexes.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,15 @@ def test_multiindex_get_level_values() -> None:
6464
check(assert_type(i1, pd.Index), pd.Index)
6565

6666

67+
def test_multiindex_initialization() -> None:
68+
check(
69+
assert_type(
70+
pd.MultiIndex([[1], [4]], codes=[[0], [0]], name=["a", "b"]), pd.MultiIndex
71+
),
72+
pd.MultiIndex,
73+
)
74+
75+
6776
def test_index_tolist() -> None:
6877
i1 = pd.Index([1, 2, 3])
6978
check(assert_type(i1.tolist(), list[int]), list, int)

0 commit comments

Comments
 (0)