diff --git a/pandas-stubs/core/indexes/multi.pyi b/pandas-stubs/core/indexes/multi.pyi index 75ecd850b..906df9bbe 100644 --- a/pandas-stubs/core/indexes/multi.pyi +++ b/pandas-stubs/core/indexes/multi.pyi @@ -16,6 +16,7 @@ from pandas.core.indexes.base import Index from typing_extensions import Self from pandas._typing import ( + Axes, Dtype, DtypeArg, HashableT, @@ -27,31 +28,41 @@ from pandas._typing import ( class MultiIndex(Index[Any]): def __new__( cls, - levels=..., - codes=..., - sortorder=..., + levels: Sequence[SequenceNotStr[Hashable]] = ..., + codes: Sequence[Sequence[int]] = ..., + sortorder: int | None = ..., names: SequenceNotStr[Hashable] = ..., - dtype=..., - copy=..., + copy: bool = ..., name: SequenceNotStr[Hashable] = ..., verify_integrity: bool = ..., - _set_identity: bool = ..., ) -> Self: ... @classmethod def from_arrays( - cls, arrays, sortorder=..., names: SequenceNotStr[Hashable] = ... + cls, + arrays: Sequence[Axes], + sortorder: int | None = ..., + names: SequenceNotStr[Hashable] = ..., ) -> Self: ... @classmethod def from_tuples( - cls, tuples, sortorder=..., names: SequenceNotStr[Hashable] = ... + cls, + tuples: Sequence[tuple[Hashable, ...]], + sortorder: int | None = ..., + names: SequenceNotStr[Hashable] = ..., ) -> Self: ... @classmethod def from_product( - cls, iterables, sortorder=..., names: SequenceNotStr[Hashable] = ... + cls, + iterables: Sequence[SequenceNotStr[Hashable]], + sortorder: int | None = ..., + names: SequenceNotStr[Hashable] = ..., ) -> Self: ... @classmethod def from_frame( - cls, df, sortorder=..., names: SequenceNotStr[Hashable] = ... + cls, + df: pd.DataFrame, + sortorder: int | None = ..., + names: SequenceNotStr[Hashable] = ..., ) -> Self: ... @property def shape(self): ... diff --git a/tests/test_indexes.py b/tests/test_indexes.py index 06d6d0d14..dedff599e 100644 --- a/tests/test_indexes.py +++ b/tests/test_indexes.py @@ -64,7 +64,7 @@ def test_multiindex_get_level_values() -> None: check(assert_type(i1, pd.Index), pd.Index) -def test_multiindex_constructor() -> None: +def test_multiindex_constructors() -> None: check( assert_type( pd.MultiIndex([[1], [4]], codes=[[0], [0]], name=["a", "b"]), pd.MultiIndex @@ -73,10 +73,35 @@ def test_multiindex_constructor() -> None: ) check( assert_type( - pd.MultiIndex([[1], [4]], codes=[[0], [0]], names=["a", "b"]), pd.MultiIndex + pd.MultiIndex( + [[1], [4]], + codes=[[0], [0]], + names=["a", "b"], + sortorder=0, + copy=True, + verify_integrity=True, + ), + pd.MultiIndex, + ), + pd.MultiIndex, + ) + check( + assert_type(pd.MultiIndex.from_arrays([[1], [4]]), pd.MultiIndex), pd.MultiIndex + ) + check( + assert_type( + pd.MultiIndex.from_arrays([np.arange(3), np.arange(3)]), pd.MultiIndex ), pd.MultiIndex, ) + check( + assert_type(pd.MultiIndex.from_tuples([(1, 3), (2, 4)]), pd.MultiIndex), + pd.MultiIndex, + ) + check( + assert_type(pd.MultiIndex.from_frame(pd.DataFrame({"a": [1]})), pd.MultiIndex), + pd.MultiIndex, + ) def test_index_tolist() -> None: