@@ -4857,6 +4857,7 @@ def _concat(self, to_concat: list[Index], name: Hashable) -> Index:
4857
4857
result = concat_compat (to_concat_vals )
4858
4858
return Index ._with_infer (result , name = name )
4859
4859
4860
+ @final
4860
4861
def putmask (self , mask , value ) -> Index :
4861
4862
"""
4862
4863
Return a new Index of the values set with the mask.
@@ -4879,19 +4880,24 @@ def putmask(self, mask, value) -> Index:
4879
4880
try :
4880
4881
converted = self ._validate_fill_value (value )
4881
4882
except (ValueError , TypeError ) as err :
4882
- if is_object_dtype (self ):
4883
+ if is_object_dtype (self ): # pragma: no cover
4883
4884
raise err
4884
4885
4885
4886
dtype = self ._find_common_type_compat (value )
4886
4887
return self .astype (dtype ).putmask (mask , value )
4887
4888
4888
4889
values = self ._values .copy ()
4889
- # error: Argument 1 to "setitem_datetimelike_compat" has incompatible type
4890
- # "Union[ExtensionArray, ndarray]"; expected "ndarray"
4891
- converted = setitem_datetimelike_compat (
4892
- values , mask .sum (), converted # type: ignore[arg-type]
4893
- )
4894
- np .putmask (values , mask , converted )
4890
+
4891
+ if isinstance (values , np .ndarray ):
4892
+ converted = setitem_datetimelike_compat (values , mask .sum (), converted )
4893
+ np .putmask (values , mask , converted )
4894
+
4895
+ else :
4896
+ # Note: we use the original value here, not converted, as
4897
+ # _validate_fill_value is not idempotent
4898
+ # error: "ExtensionArray" has no attribute "putmask"
4899
+ values .putmask (mask , value ) # type: ignore[attr-defined]
4900
+
4895
4901
return self ._shallow_copy (values )
4896
4902
4897
4903
def equals (self , other : Any ) -> bool :
0 commit comments