Skip to content

Commit adff421

Browse files
author
MarcoGorelli
committed
share paths
1 parent a08b0ef commit adff421

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

pandas/_libs/tslibs/strptime.pyx

+7-2
Original file line numberDiff line numberDiff line change
@@ -235,8 +235,13 @@ def array_strptime(
235235
out_local = 0
236236
out_tzoffset = 0
237237
iresult[i] = value
238-
check_dts_bounds(&dts)
239-
238+
try:
239+
check_dts_bounds(&dts)
240+
except ValueError:
241+
if is_coerce:
242+
iresult[i] = NPY_NAT
243+
continue
244+
raise
240245
continue
241246

242247
# exact matching

pandas/tests/tools/test_to_datetime.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -1737,8 +1737,8 @@ def test_dataframe_coerce(self, cache):
17371737
df2 = DataFrame({"year": [2015, 2016], "month": [2, 20], "day": [4, 5]})
17381738

17391739
msg = (
1740-
"cannot assemble the datetimes: time data .+ does not "
1741-
r"match format '%Y%m%d' \(match\)"
1740+
r"cannot assemble the datetimes: time data .+ at position 1 doesn\'t "
1741+
r"match format \"%Y%m%d\""
17421742
)
17431743
with pytest.raises(ValueError, match=msg):
17441744
to_datetime(df2, cache=cache)
@@ -1814,7 +1814,10 @@ def test_dataframe_mixed(self, cache):
18141814
def test_dataframe_float(self, cache):
18151815
# float
18161816
df = DataFrame({"year": [2000, 2001], "month": [1.5, 1], "day": [1, 1]})
1817-
msg = "cannot assemble the datetimes: unconverted data remains: 1"
1817+
msg = (
1818+
'cannot assemble the datetimes: time data "20000151" at position 0 '
1819+
'doesn\'t match format "%Y%m%d"'
1820+
)
18181821
with pytest.raises(ValueError, match=msg):
18191822
to_datetime(df, cache=cache)
18201823

0 commit comments

Comments
 (0)