Skip to content
Prev Previous commit
Next Next commit
BUG: refine MultiIndex key type check to allow compatible numpy scala…
…rs (GH#55969)
  • Loading branch information
Roxicaro committed Oct 24, 2025
commit 78f3654ff6e1fbc500d07f7afb29c8e31c057dde
14 changes: 14 additions & 0 deletions pandas/core/indexes/multi.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
Iterable,
Sequence,
)
import datetime
from functools import wraps
from itertools import zip_longest
from sys import getsizeof
Expand Down Expand Up @@ -3619,6 +3620,19 @@ def _is_key_type_compatible(self, key, level):
# Same type → OK
if isinstance(key, level_type):
return True
# Allow Python int for numpy integer types
if isinstance(level_type, np.integer) and isinstance(key, int):
return True

# Allow Python float for numpy float types
if isinstance(level_type, np.floating) and isinstance(key, float):
return True

# Allow subclasses of datetime.date for datetime levels
if isinstance(level_type, datetime.date) and isinstance(key, datetime.date):
return True

return False

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