Skip to content

Commit 15a73e1

Browse files
committed
BUG: refine MultiIndex key type check to allow compatible numpy scalars (GH#55969)
1 parent 8fd2619 commit 15a73e1

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

pandas/core/indexes/multi.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
Iterable,
99
Sequence,
1010
)
11+
import datetime
1112
from functools import wraps
1213
from itertools import zip_longest
1314
from sys import getsizeof
@@ -3619,6 +3620,19 @@ def _is_key_type_compatible(self, key, level):
36193620
# Same type → OK
36203621
if isinstance(key, level_type):
36213622
return True
3623+
# Allow Python int for numpy integer types
3624+
if isinstance(level_type, np.integer) and isinstance(key, int):
3625+
return True
3626+
3627+
# Allow Python float for numpy float types
3628+
if isinstance(level_type, np.floating) and isinstance(key, float):
3629+
return True
3630+
3631+
# Allow subclasses of datetime.date for datetime levels
3632+
if isinstance(level_type, datetime.date) and isinstance(key, datetime.date):
3633+
return True
3634+
3635+
return False
36223636

36233637
def _get_level_indexer(
36243638
self, key, level: int = 0, indexer: npt.NDArray[np.bool_] | None = None

0 commit comments

Comments
 (0)