Skip to content

Commit 20fc145

Browse files
author
MarcoGorelli
committed
wip
1 parent c940600 commit 20fc145

File tree

3 files changed

+17
-9
lines changed

3 files changed

+17
-9
lines changed

pandas/_libs/tslibs/strptime.pyx

+2-1
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,8 @@ def array_strptime(
396396

397397
result_timezone[i] = tz
398398

399-
except (ValueError, OutOfBoundsDatetime):
399+
except (ValueError, OutOfBoundsDatetime) as ex:
400+
ex.args = (str(ex) + f" at position {i}", )
400401
if is_coerce:
401402
iresult[i] = NPY_NAT
402403
continue

pandas/tests/io/parser/test_parse_dates.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1717,7 +1717,7 @@ def test_parse_multiple_delimited_dates_with_swap_warnings():
17171717
# GH46210
17181718
with pytest.raises(
17191719
ValueError,
1720-
match=r"^time data '31/05/2000' does not match format '%m/%d/%Y' \(match\)$",
1720+
match=r"^time data '31/05/2000' does not match format '%m/%d/%Y' \(match\) at position 1$",
17211721
):
17221722
pd.to_datetime(["01/01/2000", "31/05/2000", "31/05/2001", "01/02/2000"])
17231723

pandas/tests/tools/test_to_datetime.py

+14-7
Original file line numberDiff line numberDiff line change
@@ -1093,7 +1093,7 @@ def test_datetime_bool_arrays_mixed(self, cache):
10931093
to_datetime([False, datetime.today()], cache=cache)
10941094
with pytest.raises(
10951095
ValueError,
1096-
match=r"^time data 'True' does not match format '%Y%m%d' \(match\)$",
1096+
match=r"^time data 'True' does not match format '%Y%m%d' \(match\) at position 1$",
10971097
):
10981098
to_datetime(["20130101", True], cache=cache)
10991099
tm.assert_index_equal(
@@ -2072,7 +2072,9 @@ def test_to_datetime_on_datetime64_series(self, cache):
20722072
def test_to_datetime_with_space_in_series(self, cache):
20732073
# GH 6428
20742074
ser = Series(["10/18/2006", "10/18/2008", " "])
2075-
msg = r"^time data ' ' does not match format '%m/%d/%Y' \(match\)$"
2075+
msg = (
2076+
r"^time data ' ' does not match format '%m/%d/%Y' \(match\) at position 2$"
2077+
)
20762078
with pytest.raises(ValueError, match=msg):
20772079
to_datetime(ser, errors="raise", cache=cache)
20782080
result_coerce = to_datetime(ser, errors="coerce", cache=cache)
@@ -2342,7 +2344,7 @@ def test_dayfirst_warnings_invalid_input(self):
23422344

23432345
with pytest.raises(
23442346
ValueError,
2345-
match=r"time data '03/30/2011' does not match format '%d/%m/%Y' \(match\)$",
2347+
match=r"time data '03/30/2011' does not match format '%d/%m/%Y' \(match\) at position 1$",
23462348
):
23472349
to_datetime(arr, dayfirst=True)
23482350

@@ -2923,17 +2925,22 @@ def test_incorrect_value_exception(self):
29232925
to_datetime(["today", "yesterday"])
29242926

29252927
@pytest.mark.parametrize(
2926-
"format, warning", [(None, UserWarning), ("%Y-%m-%d %H:%M:%S", None)]
2928+
"format, warning",
2929+
[
2930+
(None, UserWarning),
2931+
("%Y-%m-%d %H:%M:%S", None),
2932+
("%Y-%d-%m %H:%M:%S", None),
2933+
],
29272934
)
29282935
def test_to_datetime_out_of_bounds_with_format_arg(self, format, warning):
29292936
# see gh-23830
29302937
msg = (
2931-
"Out of bounds nanosecond timestamp: 2417-10-27 00:00:00 "
2932-
"present at position 0"
2938+
r"Out of bounds nanosecond timestamp: 2417-10-10 00:00:00"
2939+
r".* at position 0"
29332940
)
29342941
with pytest.raises(OutOfBoundsDatetime, match=msg):
29352942
with tm.assert_produces_warning(warning, match="Could not infer format"):
2936-
to_datetime("2417-10-27 00:00:00", format=format)
2943+
to_datetime("2417-10-10 00:00:00", format=format)
29372944

29382945
@pytest.mark.parametrize(
29392946
"arg, origin, expected_str",

0 commit comments

Comments
 (0)