@@ -392,16 +392,15 @@ cdef _TSObject convert_datetime_to_tsobject(datetime ts, object tz,
392
392
return obj
393
393
394
394
395
- cdef _TSObject create_tsobject_tz_using_offset(int64_t value ,
395
+ cdef _TSObject create_tsobject_tz_using_offset(npy_datetimestruct dts ,
396
396
int tzoffset, object tz = None ):
397
397
"""
398
- Convert a numpy datetime64 `value `, along with initial timezone offset
398
+ Convert a datetimestruct `dts `, along with initial timezone offset
399
399
`tzoffset` to a _TSObject (with timezone object `tz` - optional).
400
400
401
401
Parameters
402
402
----------
403
- value: int64_t
404
- numpy dt64
403
+ dts: npy_datetimestruct
405
404
tzoffset: int
406
405
tz : tzinfo or None
407
406
timezone for the timezone-aware output.
@@ -411,12 +410,14 @@ cdef _TSObject create_tsobject_tz_using_offset(int64_t value,
411
410
obj : _TSObject
412
411
"""
413
412
cdef:
414
- _TSObject obj
413
+ _TSObject obj = _TSObject()
414
+ int64_t value # numpy dt64
415
415
datetime dt
416
416
417
- tzinfo = pytz.FixedOffset(tzoffset)
418
- value = tz_convert_single(value, tzinfo, UTC)
419
- obj = convert_to_tsobject(value, tzinfo, None , 0 , 0 )
417
+ value = dtstruct_to_dt64(& dts)
418
+ obj.dts = dts
419
+ obj.tzinfo = pytz.FixedOffset(tzoffset)
420
+ obj.value = tz_convert_single(value, obj.tzinfo, UTC)
420
421
if tz is None :
421
422
check_overflows(obj)
422
423
return obj
@@ -459,7 +460,6 @@ cdef _TSObject convert_str_to_tsobject(object ts, object tz, object unit,
459
460
"""
460
461
cdef:
461
462
npy_datetimestruct dts
462
- int64_t value # numpy dt64
463
463
int out_local = 0 , out_tzoffset = 0
464
464
bint do_parse_datetime_string = False
465
465
@@ -487,12 +487,11 @@ cdef _TSObject convert_str_to_tsobject(object ts, object tz, object unit,
487
487
try :
488
488
if not string_to_dts_failed:
489
489
check_dts_bounds(& dts)
490
- value = dtstruct_to_dt64(& dts)
491
490
if out_local == 1 :
492
- return create_tsobject_tz_using_offset(value ,
491
+ return create_tsobject_tz_using_offset(dts ,
493
492
out_tzoffset, tz)
494
493
else :
495
- ts = value
494
+ ts = dtstruct_to_dt64( & dts)
496
495
if tz is not None :
497
496
# shift for localize_tso
498
497
ts = tz_localize_to_utc(np.array([ts], dtype = ' i8' ), tz,
0 commit comments