@@ -884,6 +884,8 @@ def _engine(
884884 # error: Item "ExtensionArray" of "Union[ExtensionArray,
885885 # ndarray[Any, Any]]" has no attribute "_ndarray" [union-attr]
886886 target_values = self ._data ._ndarray # type: ignore[union-attr]
887+ elif is_string_dtype (self .dtype ) and not is_object_dtype (self .dtype ):
888+ return libindex .StringObjectEngine (target_values , self .dtype .na_value ) # type: ignore[union-attr]
887889
888890 # error: Argument 1 to "ExtensionEngine" has incompatible type
889891 # "ndarray[Any, Any]"; expected "ExtensionArray"
@@ -6133,7 +6135,6 @@ def _should_fallback_to_positional(self) -> bool:
61336135 def get_indexer_non_unique (
61346136 self , target
61356137 ) -> tuple [npt .NDArray [np .intp ], npt .NDArray [np .intp ]]:
6136- target = ensure_index (target )
61376138 target = self ._maybe_cast_listlike_indexer (target )
61386139
61396140 if not self ._should_compare (target ) and not self ._should_partial_index (target ):
@@ -6695,7 +6696,16 @@ def _maybe_cast_listlike_indexer(self, target) -> Index:
66956696 """
66966697 Analogue to maybe_cast_indexer for get_indexer instead of get_loc.
66976698 """
6698- return ensure_index (target )
6699+ target_index = ensure_index (target )
6700+ if (
6701+ not hasattr (target , "dtype" )
6702+ and self .dtype == object
6703+ and target_index .dtype == "string"
6704+ ):
6705+ # If we started with a list-like, avoid inference to string dtype if self
6706+ # is object dtype (coercing to string dtype will alter the missing values)
6707+ target_index = Index (target , dtype = self .dtype )
6708+ return target_index
66996709
67006710 @final
67016711 def _validate_indexer (
0 commit comments