@@ -19,6 +19,7 @@ cimport tslib
19
19
from hashtable cimport *
20
20
from pandas._libs import tslib, algos, hashtable as _hash
21
21
from pandas._libs.tslib import Timestamp, Timedelta
22
+ from datetime import datetime, timedelta
22
23
23
24
from datetime cimport (get_datetime64_value, _pydatetime_to_dts,
24
25
pandas_datetimestruct)
@@ -507,24 +508,30 @@ cdef class TimedeltaEngine(DatetimeEngine):
507
508
return ' m8[ns]'
508
509
509
510
cpdef convert_scalar(ndarray arr, object value):
511
+ # we don't turn intgers
512
+ # into datetimes/timedeltas
513
+
510
514
if arr.descr.type_num == NPY_DATETIME:
511
515
if isinstance (value, np.ndarray):
512
516
pass
513
- elif isinstance (value, Timestamp ):
514
- return value.value
517
+ elif isinstance (value, datetime ):
518
+ return Timestamp( value) .value
515
519
elif value is None or value != value:
516
520
return iNaT
517
- else :
521
+ elif util.is_string_object(value) :
518
522
return Timestamp(value).value
523
+ raise ValueError (" cannot set a Timestamp with a non-timestamp" )
524
+
519
525
elif arr.descr.type_num == NPY_TIMEDELTA:
520
526
if isinstance (value, np.ndarray):
521
527
pass
522
- elif isinstance (value, Timedelta ):
523
- return value.value
528
+ elif isinstance (value, timedelta ):
529
+ return Timedelta( value) .value
524
530
elif value is None or value != value:
525
531
return iNaT
526
- else :
532
+ elif util.is_string_object(value) :
527
533
return Timedelta(value).value
534
+ raise ValueError (" cannot set a Timedelta with a non-timedelta" )
528
535
529
536
if issubclass (arr.dtype.type, (np.integer, np.bool_)):
530
537
if util.is_float_object(value) and value != value:
0 commit comments