@@ -581,55 +581,62 @@ cdef _TSObject _convert_str_to_tsobject(object ts, tzinfo tz, str unit,
581
581
"""
582
582
cdef:
583
583
npy_datetimestruct dts
584
- int out_local = 0 , out_tzoffset = 0
585
- bint do_parse_datetime_string = False
584
+ int out_local = 0 , out_tzoffset = 0 , string_to_dts_failed
585
+ datetime dt
586
+ int64_t ival
586
587
587
588
if len (ts) == 0 or ts in nat_strings:
588
589
ts = NaT
590
+ obj = _TSObject()
591
+ obj.value = NPY_NAT
592
+ obj.tzinfo = tz
593
+ return obj
589
594
elif ts == ' now' :
590
595
# Issue 9000, we short-circuit rather than going
591
596
# into np_datetime_strings which returns utc
592
- ts = datetime.now(tz)
597
+ dt = datetime.now(tz)
593
598
elif ts == ' today' :
594
599
# Issue 9000, we short-circuit rather than going
595
600
# into np_datetime_strings which returns a normalized datetime
596
- ts = datetime.now(tz)
601
+ dt = datetime.now(tz)
597
602
# equiv: datetime.today().replace(tzinfo=tz)
598
603
else :
599
604
string_to_dts_failed = _string_to_dts(
600
605
ts, & dts, & out_local,
601
606
& out_tzoffset, False
602
607
)
603
- try :
604
- if not string_to_dts_failed :
608
+ if not string_to_dts_failed :
609
+ try :
605
610
check_dts_bounds(& dts)
606
611
if out_local == 1 :
607
612
return _create_tsobject_tz_using_offset(dts,
608
613
out_tzoffset, tz)
609
614
else :
610
- ts = dtstruct_to_dt64(& dts)
615
+ ival = dtstruct_to_dt64(& dts)
611
616
if tz is not None :
612
617
# shift for _localize_tso
613
- ts = tz_localize_to_utc_single(ts , tz,
614
- ambiguous = " raise" )
618
+ ival = tz_localize_to_utc_single(ival , tz,
619
+ ambiguous = " raise" )
615
620
616
- except OutOfBoundsDatetime:
617
- # GH#19382 for just-barely-OutOfBounds falling back to dateutil
618
- # parser will return incorrect result because it will ignore
619
- # nanoseconds
620
- raise
621
+ return convert_to_tsobject(ival, tz, None , False , False )
621
622
622
- except ValueError :
623
- do_parse_datetime_string = True
623
+ except OutOfBoundsDatetime:
624
+ # GH#19382 for just-barely-OutOfBounds falling back to dateutil
625
+ # parser will return incorrect result because it will ignore
626
+ # nanoseconds
627
+ raise
624
628
625
- if string_to_dts_failed or do_parse_datetime_string:
626
- try :
627
- ts = parse_datetime_string(ts, dayfirst = dayfirst,
628
- yearfirst = yearfirst)
629
- except (ValueError , OverflowError ):
630
- raise ValueError (" could not convert string to Timestamp" )
629
+ except ValueError :
630
+ # Fall through to parse_datetime_string
631
+ pass
632
+
633
+ try :
634
+ dt = parse_datetime_string(ts, dayfirst = dayfirst,
635
+ yearfirst = yearfirst)
636
+ except (ValueError , OverflowError ):
637
+ raise ValueError (" could not convert string to Timestamp" )
631
638
632
- return convert_to_tsobject(ts , tz, unit, dayfirst, yearfirst )
639
+ return convert_datetime_to_tsobject(dt , tz)
633
640
634
641
635
642
cdef inline check_overflows(_TSObject obj):
@@ -688,12 +695,8 @@ cdef inline void _localize_tso(_TSObject obj, tzinfo tz):
688
695
Sets obj.tzinfo inplace, alters obj.dts inplace.
689
696
"""
690
697
cdef:
691
- ndarray[int64_t] trans
692
- int64_t[::1 ] deltas
693
698
int64_t local_val
694
- int64_t* tdata
695
- Py_ssize_t pos, ntrans, outpos = - 1
696
- str typ
699
+ Py_ssize_t outpos = - 1
697
700
698
701
assert obj.tzinfo is None
699
702
0 commit comments