Skip to content

REF: re-use validate_listlike for _convert_arr_indexer #36415

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 17, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 6 additions & 15 deletions pandas/core/indexes/datetimelike.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

from pandas._libs import NaT, Timedelta, iNaT, join as libjoin, lib
from pandas._libs.tslibs import BaseOffset, Resolution, Tick, timezones
from pandas._libs.tslibs.parsing import DateParseError
from pandas._typing import Callable, Label
from pandas.compat.numpy import function as nv
from pandas.errors import AbstractMethodError
Expand All @@ -31,7 +30,6 @@
from pandas.core.arrays.datetimelike import DatetimeLikeArrayMixin
from pandas.core.base import IndexOpsMixin
import pandas.core.common as com
from pandas.core.construction import array as pd_array, extract_array
import pandas.core.indexes.base as ibase
from pandas.core.indexes.base import Index, _index_shared_docs
from pandas.core.indexes.extension import (
Expand Down Expand Up @@ -594,19 +592,12 @@ def _wrap_joined_index(self, joined: np.ndarray, other):

@doc(Index._convert_arr_indexer)
def _convert_arr_indexer(self, keyarr):
if lib.infer_dtype(keyarr) == "string":
# Weak reasoning that indexer is a list of strings
# representing datetime or timedelta or period
try:
extension_arr = pd_array(keyarr, self.dtype)
except (ValueError, DateParseError):
# Fail to infer keyarr from self.dtype
return keyarr

converted_arr = extract_array(extension_arr, extract_numpy=True)
else:
converted_arr = com.asarray_tuplesafe(keyarr)
return converted_arr
try:
return self._data._validate_listlike(
keyarr, "convert_arr_indexer", cast_str=True, allow_object=True
)
except (ValueError, TypeError):
return com.asarray_tuplesafe(keyarr)


class DatetimeTimedeltaMixin(DatetimeIndexOpsMixin, Int64Index):
Expand Down