@@ -40,14 +40,17 @@ class AmbiguousIndexError(PandasError, KeyError):
40
40
41
41
42
42
_POSSIBLY_CAST_DTYPES = set ([np .dtype (t )
43
- for t in ['M8[ns]' , 'm8[ns]' , 'O' , 'int8' ,
43
+ for t in ['M8[ns]' , '>M8[ns]' , '<M8[ns]' ,
44
+ 'm8[ns]' , '>m8[ns]' , '<m8[ns]' ,
45
+ 'O' , 'int8' ,
44
46
'uint8' , 'int16' , 'uint16' , 'int32' ,
45
47
'uint32' , 'int64' , 'uint64' ]])
46
48
47
49
_NS_DTYPE = np .dtype ('M8[ns]' )
48
50
_TD_DTYPE = np .dtype ('m8[ns]' )
49
51
_INT64_DTYPE = np .dtype (np .int64 )
50
- _DATELIKE_DTYPES = set ([np .dtype (t ) for t in ['M8[ns]' , 'm8[ns]' ]])
52
+ _DATELIKE_DTYPES = set ([np .dtype (t ) for t in ['M8[ns]' , '<M8[ns]' , '>M8[ns]' ,
53
+ 'm8[ns]' , '<m8[ns]' , '>m8[ns]' ]])
51
54
52
55
53
56
# define abstract base classes to enable isinstance type checking on our
@@ -1572,11 +1575,17 @@ def _possibly_cast_to_datetime(value, dtype, coerce=False):
1572
1575
1573
1576
# force the dtype if needed
1574
1577
if is_datetime64 and dtype != _NS_DTYPE :
1575
- raise TypeError (
1576
- "cannot convert datetimelike to dtype [%s]" % dtype )
1578
+ if dtype .name == 'datetime64[ns]' :
1579
+ dtype = _NS_DTYPE
1580
+ else :
1581
+ raise TypeError (
1582
+ "cannot convert datetimelike to dtype [%s]" % dtype )
1577
1583
elif is_timedelta64 and dtype != _TD_DTYPE :
1578
- raise TypeError (
1579
- "cannot convert timedeltalike to dtype [%s]" % dtype )
1584
+ if dtype .name == 'timedelta64[ns]' :
1585
+ dtype = _TD_DTYPE
1586
+ else :
1587
+ raise TypeError (
1588
+ "cannot convert timedeltalike to dtype [%s]" % dtype )
1580
1589
1581
1590
if np .isscalar (value ):
1582
1591
if value == tslib .iNaT or isnull (value ):
0 commit comments