@@ -40,14 +40,17 @@ class AmbiguousIndexError(PandasError, KeyError):
4040
4141
4242_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' ,
4446 'uint8' , 'int16' , 'uint16' , 'int32' ,
4547 'uint32' , 'int64' , 'uint64' ]])
4648
4749_NS_DTYPE = np .dtype ('M8[ns]' )
4850_TD_DTYPE = np .dtype ('m8[ns]' )
4951_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]' ]])
5154
5255
5356# define abstract base classes to enable isinstance type checking on our
@@ -1572,11 +1575,17 @@ def _possibly_cast_to_datetime(value, dtype, coerce=False):
15721575
15731576 # force the dtype if needed
15741577 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 )
15771583 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 )
15801589
15811590 if np .isscalar (value ):
15821591 if value == tslib .iNaT or isnull (value ):
0 commit comments