Skip to content

Commit 1233eb4

Browse files
committed
removed extra 'check_dts_bounds' call and 'try/except Exception:' block
1 parent 389253a commit 1233eb4

File tree

1 file changed

+13
-15
lines changed

1 file changed

+13
-15
lines changed

pandas/_libs/tslibs/conversion.pyx

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,7 @@ cdef _TSObject convert_str_to_tsobject(object ts, object tz, object unit,
423423
_TSObject obj
424424
int out_local = 0, out_tzoffset = 0
425425
datetime dt
426+
bint do_parse_datetime_string = False
426427

427428
if tz is not None:
428429
tz = maybe_get_tz(tz)
@@ -447,21 +448,14 @@ cdef _TSObject convert_str_to_tsobject(object ts, object tz, object unit,
447448
ts, &obj.dts, &out_local,
448449
&out_tzoffset, False
449450
)
450-
if string_to_dts_failed:
451-
try:
452-
ts = parse_datetime_string(ts, dayfirst=dayfirst,
453-
yearfirst=yearfirst)
454-
except Exception:
455-
raise ValueError("could not convert string to Timestamp")
456-
else:
457-
try:
451+
try:
452+
if not string_to_dts_failed:
458453
obj.value = dtstruct_to_dt64(&obj.dts)
459454
check_dts_bounds(&obj.dts)
460455
if out_local == 1:
461456
obj.tzinfo = pytz.FixedOffset(out_tzoffset)
462457
obj.value = tz_convert_single(obj.value, obj.tzinfo, UTC)
463458
if tz is None:
464-
check_dts_bounds(&obj.dts)
465459
check_overflows(obj)
466460
return obj
467461
else:
@@ -482,13 +476,17 @@ cdef _TSObject convert_str_to_tsobject(object ts, object tz, object unit,
482476
ts = tz_localize_to_utc(np.array([ts], dtype='i8'), tz,
483477
ambiguous='raise')[0]
484478

485-
except OutOfBoundsDatetime:
486-
# GH#19382 for just-barely-OutOfBounds falling back to dateutil
487-
# parser will return incorrect result because it will ignore
488-
# nanoseconds
489-
raise
479+
except OutOfBoundsDatetime:
480+
# GH#19382 for just-barely-OutOfBounds falling back to dateutil
481+
# parser will return incorrect result because it will ignore
482+
# nanoseconds
483+
raise
484+
485+
except ValueError:
486+
do_parse_datetime_string = True
490487

491-
except ValueError:
488+
finally:
489+
if string_to_dts_failed or do_parse_datetime_string:
492490
try:
493491
ts = parse_datetime_string(ts, dayfirst=dayfirst,
494492
yearfirst=yearfirst)

0 commit comments

Comments
 (0)