Skip to content

Commit 2a96991

Browse files
committed
improving OutOfBoundsDatetime exception messages
1 parent fbb3e37 commit 2a96991

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

pandas/_libs/tslib.pyx

+3-3
Original file line numberDiff line numberDiff line change
@@ -652,7 +652,7 @@ cpdef array_to_datetime(
652652
else:
653653
raise TypeError(f"{type(val)} is not convertible to datetime")
654654

655-
except OutOfBoundsDatetime:
655+
except OutOfBoundsDatetime as ex:
656656
if is_coerce:
657657
iresult[i] = NPY_NAT
658658
continue
@@ -664,11 +664,11 @@ cpdef array_to_datetime(
664664

665665
# Still raise OutOfBoundsDatetime,
666666
# as error message is informative.
667-
raise OutOfBoundsDatetime(f"Cannot convert \"{val}\" at position {i} to datetime")
667+
raise OutOfBoundsDatetime(f"Cannot convert \"{val}\" at position {i} to datetime") from ex
668668

669669
assert is_ignore
670670
return values, tz_out
671-
raise OutOfBoundsDatetime(f"Cannot convert \"{val}\" at position {i} to datetime")
671+
raise OutOfBoundsDatetime(f"Cannot convert \"{val}\" at position {i} to datetime") from ex
672672

673673
except OutOfBoundsDatetime:
674674
if is_raise:

0 commit comments

Comments
 (0)