File tree Expand file tree Collapse file tree 1 file changed +10
-4
lines changed Expand file tree Collapse file tree 1 file changed +10
-4
lines changed Original file line number Diff line number Diff line change @@ -6556,10 +6556,16 @@ def _maybe_cast_listlike_indexer(self, target) -> Index:
65566556 """
65576557 Analogue to maybe_cast_indexer for get_indexer instead of get_loc.
65586558 """
6559- if not hasattr (target , "dtype" ) and self .dtype == object :
6560- # Avoid inference for object since we are casting back later anyway
6561- return Index (target , dtype = self .dtype )
6562- return ensure_index (target )
6559+ target_index = ensure_index (target )
6560+ if (
6561+ not hasattr (target , "dtype" )
6562+ and self .dtype == object
6563+ and target_index .dtype == "string"
6564+ ):
6565+ # If we started with a list-like, avoid inference to string dtype if self
6566+ # is object dtype (coercing to string dtype will alter the missing values)
6567+ target_index = Index (target , dtype = self .dtype )
6568+ return target_index
65636569
65646570 @final
65656571 def _validate_indexer (
You can’t perform that action at this time.
0 commit comments