96
96
from pandas .core .dtypes .generic import (
97
97
ABCDataFrame ,
98
98
ABCExtensionArray ,
99
- ABCIndex ,
100
99
ABCSeries ,
101
100
)
102
101
from pandas .core .dtypes .inference import is_list_like
@@ -1389,7 +1388,7 @@ def maybe_castable(dtype: np.dtype) -> bool:
1389
1388
1390
1389
1391
1390
def maybe_infer_to_datetimelike (
1392
- value : Union [ArrayLike , Scalar ], convert_dates : bool = False
1391
+ value : Union [np . ndarray , List ], convert_dates : bool = False
1393
1392
):
1394
1393
"""
1395
1394
we might have a array (or single object) that is datetime like,
@@ -1401,21 +1400,16 @@ def maybe_infer_to_datetimelike(
1401
1400
1402
1401
Parameters
1403
1402
----------
1404
- value : np.array / Series / Index / list-like
1403
+ value : np.ndarray or list
1405
1404
convert_dates : bool, default False
1406
1405
if True try really hard to convert dates (such as datetime.date), other
1407
1406
leave inferred dtype 'date' alone
1408
1407
1409
1408
"""
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 ))
1413
1411
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 )
1419
1413
1420
1414
# we only care about object dtypes
1421
1415
if not is_object_dtype (v .dtype ):
@@ -1616,7 +1610,7 @@ def maybe_cast_to_datetime(
1616
1610
elif value .dtype == object :
1617
1611
value = maybe_infer_to_datetimelike (value )
1618
1612
1619
- else :
1613
+ elif not isinstance ( value , ABCExtensionArray ) :
1620
1614
# only do this if we have an array and the dtype of the array is not
1621
1615
# setup already we are not an integer/object, so don't bother with this
1622
1616
# conversion
0 commit comments