@@ -955,10 +955,10 @@ def _possibly_cast_to_timedelta(value, coerce=True):
955
955
def _possibly_cast_to_datetime (value , dtype , coerce = False ):
956
956
""" try to cast the array/value to a datetimelike dtype, converting float nan to iNaT """
957
957
958
- if isinstance (dtype , basestring ):
959
- dtype = np .dtype (dtype )
960
-
961
958
if dtype is not None :
959
+ if isinstance (dtype , basestring ):
960
+ dtype = np .dtype (dtype )
961
+
962
962
is_datetime64 = is_datetime64_dtype (dtype )
963
963
is_timedelta64 = is_timedelta64_dtype (dtype )
964
964
@@ -984,21 +984,28 @@ def _possibly_cast_to_datetime(value, dtype, coerce = False):
984
984
except :
985
985
pass
986
986
987
- elif dtype is None :
988
- # we might have a array (or single object) that is datetime like, and no dtype is passed
989
- # don't change the value unless we find a datetime set
990
- v = value
991
- if not is_list_like (v ):
992
- v = [ v ]
993
- if len (v ):
994
- inferred_type = lib .infer_dtype (v )
995
- if inferred_type == 'datetime' :
996
- try :
997
- value = tslib .array_to_datetime (np .array (v ))
998
- except :
999
- pass
1000
- elif inferred_type == 'timedelta' :
1001
- value = _possibly_cast_to_timedelta (value )
987
+ else :
988
+
989
+ # only do this if we have an array and the dtype of the array is not setup already
990
+ # we are not an integer/object, so don't bother with this conversion
991
+ if isinstance (value , np .ndarray ) and not (issubclass (value .dtype .type , np .integer ) or value .dtype == np .object_ ):
992
+ pass
993
+
994
+ else :
995
+ # we might have a array (or single object) that is datetime like, and no dtype is passed
996
+ # don't change the value unless we find a datetime set
997
+ v = value
998
+ if not is_list_like (v ):
999
+ v = [ v ]
1000
+ if len (v ):
1001
+ inferred_type = lib .infer_dtype (v )
1002
+ if inferred_type == 'datetime' :
1003
+ try :
1004
+ value = tslib .array_to_datetime (np .array (v ))
1005
+ except :
1006
+ pass
1007
+ elif inferred_type == 'timedelta' :
1008
+ value = _possibly_cast_to_timedelta (value )
1002
1009
1003
1010
return value
1004
1011
0 commit comments