File tree 1 file changed +17
-0
lines changed
1 file changed +17
-0
lines changed Original file line number Diff line number Diff line change 59
59
is_number ,
60
60
is_object_dtype ,
61
61
is_scalar ,
62
+ is_signed_integer_dtype ,
63
+ is_unsigned_integer_dtype ,
62
64
)
63
65
from pandas .core .dtypes .dtypes import IntervalDtype
64
66
from pandas .core .dtypes .missing import is_valid_na_for_dtype
@@ -521,6 +523,7 @@ def _maybe_convert_i8(self, key):
521
523
original = key
522
524
if is_list_like (key ):
523
525
key = ensure_index (key )
526
+ key = self ._maybe_convert_numeric_to_64bit (key )
524
527
525
528
if not self ._needs_i8_conversion (key ):
526
529
return original
@@ -566,6 +569,20 @@ def _maybe_convert_i8(self, key):
566
569
567
570
return key_i8
568
571
572
+ def _maybe_convert_numeric_to_64bit (self , idx : Index ) -> Index :
573
+ # IntervalTree only supports 64 bit numpy array
574
+ dtype = idx .dtype
575
+ if np .issubclass_ (idx .dtype .type , np .number ):
576
+ return idx
577
+ elif is_signed_integer_dtype (dtype ) and dtype != np .int64 :
578
+ return idx .astype (np .int64 )
579
+ elif is_unsigned_integer_dtype (dtype ) and dtype != np .uint64 :
580
+ return idx .astype (np .uint64 )
581
+ elif is_float_dtype (dtype ) and dtype != np .float64 :
582
+ return idx .astype (np .float64 )
583
+ else :
584
+ return idx
585
+
569
586
def _searchsorted_monotonic (self , label , side : Literal ["left" , "right" ] = "left" ):
570
587
if not self .is_non_overlapping_monotonic :
571
588
raise KeyError (
You can’t perform that action at this time.
0 commit comments