@@ -861,7 +861,15 @@ def _replace_list(
861
861
"""
862
862
See BlockManager._replace_list docstring.
863
863
"""
864
- src_len = len (src_list ) - 1
864
+ # Exclude anything that we know we won't contain
865
+ pairs = [
866
+ (x , y ) for x , y in zip (src_list , dest_list ) if self ._can_hold_element (x )
867
+ ]
868
+ if not len (pairs ):
869
+ # shortcut, nothing to replace
870
+ return [self ] if inplace else [self .copy ()]
871
+
872
+ src_len = len (pairs ) - 1
865
873
866
874
def comp (s : Scalar , mask : np .ndarray , regex : bool = False ) -> np .ndarray :
867
875
"""
@@ -874,15 +882,19 @@ def comp(s: Scalar, mask: np.ndarray, regex: bool = False) -> np.ndarray:
874
882
s = maybe_box_datetimelike (s )
875
883
return compare_or_regex_search (self .values , s , regex , mask )
876
884
877
- # Calculate the mask once, prior to the call of comp
878
- # in order to avoid repeating the same computations
879
- mask = ~ isna (self .values )
885
+ if self .is_object :
886
+ # Calculate the mask once, prior to the call of comp
887
+ # in order to avoid repeating the same computations
888
+ mask = ~ isna (self .values )
889
+ masks = [comp (s [0 ], mask , regex ) for s in pairs ]
890
+ else :
891
+ # GH#38086 faster if we know we dont need to check for regex
892
+ masks = [missing .mask_missing (self .values , s [0 ]) for s in pairs ]
880
893
881
- masks = [comp (s , mask , regex ) for s in src_list ]
882
894
masks = [_extract_bool_array (x ) for x in masks ]
883
895
884
896
rb = [self if inplace else self .copy ()]
885
- for i , (src , dest ) in enumerate (zip ( src_list , dest_list ) ):
897
+ for i , (src , dest ) in enumerate (pairs ):
886
898
new_rb : List ["Block" ] = []
887
899
for blk in rb :
888
900
m = masks [i ]
@@ -1037,7 +1049,7 @@ def _putmask_simple(self, mask: np.ndarray, value: Any):
1037
1049
if lib .is_scalar (value ) and isinstance (values , np .ndarray ):
1038
1050
value = convert_scalar_for_putitemlike (value , values .dtype )
1039
1051
1040
- if self .is_extension or self .is_object :
1052
+ if self .is_extension or ( self .is_object and not lib . is_scalar ( value )) :
1041
1053
# GH#19266 using np.putmask gives unexpected results with listlike value
1042
1054
if is_list_like (value ) and len (value ) == len (values ):
1043
1055
values [mask ] = value [mask ]
0 commit comments