@@ -183,14 +183,16 @@ def _rebox_native(cls, value: int) -> Union[int, np.datetime64, np.timedelta64]:
183
183
"""
184
184
raise AbstractMethodError (cls )
185
185
186
- def _unbox_scalar (self , value : DTScalarOrNaT ) -> int :
186
+ def _unbox_scalar (self , value : DTScalarOrNaT , setitem : bool = False ) -> int :
187
187
"""
188
188
Unbox the integer value of a scalar `value`.
189
189
190
190
Parameters
191
191
----------
192
192
value : Period, Timestamp, Timedelta, or NaT
193
193
Depending on subclass.
194
+ setitem : bool, default False
195
+ Whether to check compatiblity with setitem strictness.
194
196
195
197
Returns
196
198
-------
@@ -841,6 +843,7 @@ def _validate_listlike(
841
843
if is_dtype_equal (value .categories .dtype , self .dtype ):
842
844
# TODO: do we need equal dtype or just comparable?
843
845
value = value ._internal_get_values ()
846
+ value = extract_array (value , extract_numpy = True )
844
847
845
848
if allow_object and is_object_dtype (value .dtype ):
846
849
pass
@@ -875,8 +878,7 @@ def _validate_setitem_value(self, value):
875
878
# TODO: cast_str for consistency?
876
879
value = self ._validate_scalar (value , msg , cast_str = False )
877
880
878
- self ._check_compatible_with (value , setitem = True )
879
- return self ._unbox (value )
881
+ return self ._unbox (value , setitem = True )
880
882
881
883
def _validate_insert_value (self , value ):
882
884
msg = f"cannot insert { type (self ).__name__ } with incompatible label"
@@ -886,27 +888,27 @@ def _validate_insert_value(self, value):
886
888
# TODO: if we dont have compat, should we raise or astype(object)?
887
889
# PeriodIndex does astype(object)
888
890
return value
891
+ # Note: we do not unbox here because the caller needs boxed value
892
+ # to check for freq.
889
893
890
894
def _validate_where_value (self , other ):
891
895
msg = f"Where requires matching dtype, not { type (other )} "
892
896
if not is_list_like (other ):
893
897
other = self ._validate_scalar (other , msg )
894
898
else :
895
899
other = self ._validate_listlike (other , "where" )
896
- self ._check_compatible_with (other , setitem = True )
897
900
898
- self ._check_compatible_with (other , setitem = True )
899
- return self ._unbox (other )
901
+ return self ._unbox (other , setitem = True )
900
902
901
- def _unbox (self , other ) -> Union [np .int64 , np .ndarray ]:
903
+ def _unbox (self , other , setitem : bool = False ) -> Union [np .int64 , np .ndarray ]:
902
904
"""
903
905
Unbox either a scalar with _unbox_scalar or an instance of our own type.
904
906
"""
905
907
if lib .is_scalar (other ):
906
- other = self ._unbox_scalar (other )
908
+ other = self ._unbox_scalar (other , setitem = setitem )
907
909
else :
908
910
# same type as self
909
- self ._check_compatible_with (other )
911
+ self ._check_compatible_with (other , setitem = setitem )
910
912
other = other .view ("i8" )
911
913
return other
912
914
0 commit comments