2020 is_datetime64_any_dtype ,
2121 is_float_dtype ,
2222 is_integer_dtype ,
23- is_interval ,
2423 is_interval_dtype ,
2524 is_list_like ,
2625 is_object_dtype ,
@@ -813,7 +812,9 @@ def take(self, indices, allow_fill=False, fill_value=None, axis=None, **kwargs):
813812
814813 fill_left = fill_right = fill_value
815814 if allow_fill :
816- fill_left , fill_right = self ._validate_fill_value (fill_value )
815+ if (np .asarray (indices ) == - 1 ).any ():
816+ # We have excel tests that pass fill_value=True, xref GH#36466
817+ fill_left , fill_right = self ._validate_fill_value (fill_value )
817818
818819 left_take = take (
819820 self .left , indices , allow_fill = allow_fill , fill_value = fill_left
@@ -824,20 +825,33 @@ def take(self, indices, allow_fill=False, fill_value=None, axis=None, **kwargs):
824825
825826 return self ._shallow_copy (left_take , right_take )
826827
827- def _validate_fill_value (self , value ):
828- if is_interval (value ):
829- self ._check_closed_matches (value , name = "fill_value" )
830- fill_left , fill_right = value .left , value .right
831- elif not is_scalar (value ) and notna (value ):
832- msg = (
833- "'IntervalArray.fillna' only supports filling with a "
834- "'scalar pandas.Interval or NA'. "
835- f"Got a '{ type (value ).__name__ } ' instead."
836- )
837- raise ValueError (msg )
828+ def _validate_listlike (self , value ):
829+ # list-like of intervals
830+ try :
831+ array = IntervalArray (value )
832+ # TODO: self._check_closed_matches(array, name="value")
833+ value_left , value_right = array .left , array .right
834+ except TypeError as err :
835+ # wrong type: not interval or NA
836+ msg = f"'value' should be an interval type, got { type (value )} instead."
837+ raise TypeError (msg ) from err
838+ return value_left , value_right
839+
840+ def _validate_scalar (self , value ):
841+ if isinstance (value , Interval ):
842+ self ._check_closed_matches (value , name = "value" )
843+ left , right = value .left , value .right
844+ elif is_valid_nat_for_dtype (value , self .left .dtype ):
845+ # GH#18295
846+ left = right = value
838847 else :
839- fill_left = fill_right = self .left ._na_value
840- return fill_left , fill_right
848+ raise ValueError (
849+ "can only insert Interval objects and NA into an IntervalArray"
850+ )
851+ return left , right
852+
853+ def _validate_fill_value (self , value ):
854+ return self ._validate_scalar (value )
841855
842856 def _validate_fillna_value (self , value ):
843857 if not isinstance (value , Interval ):
@@ -851,26 +865,12 @@ def _validate_fillna_value(self, value):
851865 return value .left , value .right
852866
853867 def _validate_insert_value (self , value ):
854- if isinstance (value , Interval ):
855- if value .closed != self .closed :
856- raise ValueError (
857- "inserted item must be closed on the same side as the index"
858- )
859- left_insert = value .left
860- right_insert = value .right
861- elif is_valid_nat_for_dtype (value , self .left .dtype ):
862- # GH#18295
863- left_insert = right_insert = value
864- else :
865- raise ValueError (
866- "can only insert Interval objects and NA into an IntervalIndex"
867- )
868- return left_insert , right_insert
868+ return self ._validate_scalar (value )
869869
870870 def _validate_setitem_value (self , value ):
871871 needs_float_conversion = False
872872
873- if is_scalar (value ) and isna ( value ):
873+ if is_valid_nat_for_dtype (value , self . left . dtype ):
874874 # na value: need special casing to set directly on numpy arrays
875875 if is_integer_dtype (self .dtype .subtype ):
876876 # can't set NaN on a numpy integer array
0 commit comments