File tree 1 file changed +27
-0
lines changed
1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -564,3 +564,30 @@ def _wrap_ndarray_result(self, result: np.ndarray):
564
564
# ------------------------------------------------------------------------
565
565
# String methods interface
566
566
_str_na_value = np .nan
567
+ def _validate_setitem_value (self , value ):
568
+ """
569
+ Check if we have a scalar that we can cast losslessly.
570
+
571
+ Raises
572
+ ------
573
+ TypeError
574
+ """
575
+ kind = self .dtype .kind
576
+ # TODO: get this all from np_can_hold_element?
577
+ if kind == "b" :
578
+ if lib .is_bool (value ):
579
+ return value
580
+
581
+ elif kind == "f" :
582
+ if lib .is_integer (value ) or lib .is_float (value ):
583
+ return value
584
+
585
+ else :
586
+ if lib .is_integer (value ) or (lib .is_float (value ) and value .is_integer ()):
587
+ return value
588
+ # TODO: unsigned checks
589
+
590
+ # Note: without the "str" here, the f-string rendering raises in
591
+ # py38 builds.
592
+ raise TypeError (f"Invalid value '{ str (value )} ' for dtype { self .dtype } " )
593
+
You can’t perform that action at this time.
0 commit comments