Skip to content

Commit 6865973

Browse files
committed
pandas-dev#16757: improvement of to_datetime errors
1 parent afadca4 commit 6865973

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
@@ -595,7 +595,7 @@ cpdef array_to_datetime(
595595
continue
596596
elif is_raise:
597597
raise ValueError(
598-
f"time data {val} doesn't match format specified"
598+
f"time data \"{val}\" at position {i} doesn't match format specified"
599599
)
600600
return values, tz_out
601601

@@ -607,11 +607,11 @@ cpdef array_to_datetime(
607607
# to check if all arguments have the same tzinfo
608608
tz = py_dt.utcoffset()
609609

610-
except (ValueError, OverflowError):
610+
except (ValueError, OverflowError) as err:
611611
if is_coerce:
612612
iresult[i] = NPY_NAT
613613
continue
614-
raise TypeError("invalid string coercion to datetime")
614+
raise type(err)(f"invalid string coercion to datetime for \"{val}\" at position {i}")
615615

616616
if tz is not None:
617617
seen_datetime_offset = True

0 commit comments

Comments
 (0)