Skip to content

Commit 0e1e4c2

Browse files
BUG: Fix MultiIndex.dtypes (#597) (#603)
* Fix MultiIndex.dtypes (#597) * Tighten the MultiIndex.dtypes return value to Dtype
1 parent f69f493 commit 0e1e4c2

File tree

3 files changed

+11
-0
lines changed

3 files changed

+11
-0
lines changed

pandas-stubs/_typing.pyi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,7 @@ S1 = TypeVar(
306306
int,
307307
float,
308308
complex,
309+
Dtype,
309310
Timestamp,
310311
Timedelta,
311312
Period,

pandas-stubs/core/indexes/multi.pyi

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ from typing_extensions import Self
1515

1616
from pandas._typing import (
1717
T1,
18+
Dtype,
1819
DtypeArg,
1920
HashableT,
2021
np_ndarray_anyint,
@@ -68,6 +69,8 @@ class MultiIndex(Index):
6869
def __contains__(self, key) -> bool: ...
6970
@property
7071
def dtype(self) -> np.dtype: ...
72+
@property
73+
def dtypes(self) -> pd.Series[Dtype]: ...
7174
def memory_usage(self, deep: bool = ...) -> int: ...
7275
@property
7376
def nbytes(self) -> int: ...

tests/test_indexes.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
assert_type,
1616
)
1717

18+
from pandas._typing import Dtype # noqa: F401
1819
from pandas._typing import Scalar
1920

2021
from tests import (
@@ -854,3 +855,9 @@ def test_getitem() -> None:
854855
check(assert_type(i0, pd.Index), pd.Index)
855856
check(assert_type(i0[0], Scalar), str)
856857
check(assert_type(i0[[0, 2]], pd.Index), pd.Index, str)
858+
859+
860+
def test_multiindex_dtypes():
861+
# GH-597
862+
mi = pd.MultiIndex.from_tuples([(1, 2.0), (2, 3.0)], names=["foo", "bar"])
863+
check(assert_type(mi.dtypes, "pd.Series[Dtype]"), pd.Series)

0 commit comments

Comments
 (0)