Skip to content

Commit 9dd987d

Browse files
jbrockmendelrhshadrach
authored andcommitted
REF: re-use validate_listlike for _convert_arr_indexer (pandas-dev#36415)
1 parent 1178ea5 commit 9dd987d

File tree

1 file changed

+6
-15
lines changed

1 file changed

+6
-15
lines changed

pandas/core/indexes/datetimelike.py

+6-15
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
from pandas._libs import NaT, Timedelta, iNaT, join as libjoin, lib
1010
from pandas._libs.tslibs import BaseOffset, Resolution, Tick, timezones
11-
from pandas._libs.tslibs.parsing import DateParseError
1211
from pandas._typing import Callable, Label
1312
from pandas.compat.numpy import function as nv
1413
from pandas.errors import AbstractMethodError
@@ -31,7 +30,6 @@
3130
from pandas.core.arrays.datetimelike import DatetimeLikeArrayMixin
3231
from pandas.core.base import IndexOpsMixin
3332
import pandas.core.common as com
34-
from pandas.core.construction import array as pd_array, extract_array
3533
import pandas.core.indexes.base as ibase
3634
from pandas.core.indexes.base import Index, _index_shared_docs
3735
from pandas.core.indexes.extension import (
@@ -586,19 +584,12 @@ def _wrap_joined_index(self, joined: np.ndarray, other):
586584

587585
@doc(Index._convert_arr_indexer)
588586
def _convert_arr_indexer(self, keyarr):
589-
if lib.infer_dtype(keyarr) == "string":
590-
# Weak reasoning that indexer is a list of strings
591-
# representing datetime or timedelta or period
592-
try:
593-
extension_arr = pd_array(keyarr, self.dtype)
594-
except (ValueError, DateParseError):
595-
# Fail to infer keyarr from self.dtype
596-
return keyarr
597-
598-
converted_arr = extract_array(extension_arr, extract_numpy=True)
599-
else:
600-
converted_arr = com.asarray_tuplesafe(keyarr)
601-
return converted_arr
587+
try:
588+
return self._data._validate_listlike(
589+
keyarr, "convert_arr_indexer", cast_str=True, allow_object=True
590+
)
591+
except (ValueError, TypeError):
592+
return com.asarray_tuplesafe(keyarr)
602593

603594

604595
class DatetimeTimedeltaMixin(DatetimeIndexOpsMixin, Int64Index):

0 commit comments

Comments
 (0)