File tree Expand file tree Collapse file tree 1 file changed +17
-0
lines changed Expand file tree Collapse file tree 1 file changed +17
-0
lines changed Original file line number Diff line number Diff line change 5959 is_number ,
6060 is_object_dtype ,
6161 is_scalar ,
62+ is_signed_integer_dtype ,
63+ is_unsigned_integer_dtype ,
6264)
6365from pandas .core .dtypes .dtypes import IntervalDtype
6466from pandas .core .dtypes .missing import is_valid_na_for_dtype
@@ -521,6 +523,7 @@ def _maybe_convert_i8(self, key):
521523 original = key
522524 if is_list_like (key ):
523525 key = ensure_index (key )
526+ key = self ._maybe_convert_numeric_to_64bit (key )
524527
525528 if not self ._needs_i8_conversion (key ):
526529 return original
@@ -566,6 +569,20 @@ def _maybe_convert_i8(self, key):
566569
567570 return key_i8
568571
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_ (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+
569586 def _searchsorted_monotonic (self , label , side : Literal ["left" , "right" ] = "left" ):
570587 if not self .is_non_overlapping_monotonic :
571588 raise KeyError (
You can’t perform that action at this time.
0 commit comments