Skip to content

Commit 82e4eb8

Browse files
committed
dont catch in conversion.pyx
1 parent d0cd8d8 commit 82e4eb8

File tree

3 files changed

+5
-12
lines changed

3 files changed

+5
-12
lines changed

pandas/_libs/tslibs/conversion.pyx

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -542,16 +542,9 @@ cdef _TSObject convert_str_to_tsobject(str ts, tzinfo tz, str unit,
542542
maybe_localize_tso(obj, tz, obj.creso)
543543
return obj
544544

545-
try:
546-
dt = parse_datetime_string(
547-
ts, dayfirst=dayfirst, yearfirst=yearfirst
548-
)
549-
except ValueError as err:
550-
if "out of range for month" in str(err):
551-
# dateutil raised when constructing a datetime object,
552-
# let's give a nicer exception message
553-
raise ValueError("could not convert string to Timestamp") from err
554-
raise
545+
dt = parse_datetime_string(
546+
ts, dayfirst=dayfirst, yearfirst=yearfirst
547+
)
555548

556549
return convert_datetime_to_tsobject(dt, tz)
557550

pandas/tests/io/pytables/test_select.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,7 @@ def test_frame_select(setup_path):
594594
# invalid terms
595595
df = tm.makeTimeDataFrame()
596596
store.append("df_time", df)
597-
msg = "could not convert string to Timestamp"
597+
msg = "day is out of range for month: 0"
598598
with pytest.raises(ValueError, match=msg):
599599
store.select("df_time", "index>0")
600600

pandas/tests/tools/test_to_datetime.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2791,7 +2791,7 @@ def test_day_not_in_month_coerce(self, cache, arg, format, warning):
27912791
assert isna(to_datetime(arg, errors="coerce", format=format, cache=cache))
27922792

27932793
def test_day_not_in_month_raise(self, cache):
2794-
msg = "could not convert string to Timestamp"
2794+
msg = "day is out of range for month: 2015-02-29, at position 0"
27952795
with pytest.raises(ValueError, match=msg):
27962796
with tm.assert_produces_warning(
27972797
UserWarning, match="Could not infer format"

0 commit comments

Comments
 (0)