9696from pandas .core .dtypes .generic import (
9797 ABCDataFrame ,
9898 ABCExtensionArray ,
99- ABCIndex ,
10099 ABCSeries ,
101100)
102101from pandas .core .dtypes .inference import is_list_like
@@ -1389,7 +1388,7 @@ def maybe_castable(dtype: np.dtype) -> bool:
13891388
13901389
13911390def maybe_infer_to_datetimelike (
1392- value : Union [ArrayLike , Scalar ], convert_dates : bool = False
1391+ value : Union [np . ndarray , List ], convert_dates : bool = False
13931392):
13941393 """
13951394 we might have a array (or single object) that is datetime like,
@@ -1401,21 +1400,16 @@ def maybe_infer_to_datetimelike(
14011400
14021401 Parameters
14031402 ----------
1404- value : np.array / Series / Index / list-like
1403+ value : np.ndarray or list
14051404 convert_dates : bool, default False
14061405 if True try really hard to convert dates (such as datetime.date), other
14071406 leave inferred dtype 'date' alone
14081407
14091408 """
1410- if isinstance (value , (ABCIndex , ABCExtensionArray )):
1411- if not is_object_dtype (value .dtype ):
1412- raise ValueError ("array-like value must be object-dtype" )
1409+ if not isinstance (value , (np .ndarray , list )):
1410+ raise TypeError (type (value ))
14131411
1414- v = value
1415-
1416- if not is_list_like (v ):
1417- v = [v ]
1418- v = np .array (v , copy = False )
1412+ v = np .array (value , copy = False )
14191413
14201414 # we only care about object dtypes
14211415 if not is_object_dtype (v .dtype ):
@@ -1616,7 +1610,7 @@ def maybe_cast_to_datetime(
16161610 elif value .dtype == object :
16171611 value = maybe_infer_to_datetimelike (value )
16181612
1619- else :
1613+ elif not isinstance ( value , ABCExtensionArray ) :
16201614 # only do this if we have an array and the dtype of the array is not
16211615 # setup already we are not an integer/object, so don't bother with this
16221616 # conversion
0 commit comments