@@ -481,8 +481,8 @@ def test_to_datetime_parse_timezone_malformed(self, offset):
481
481
482
482
msg = "|" .join (
483
483
[
484
- r'^time data ".*" at position 0 doesn\'t match format ".*"$' ,
485
- r'^unconverted data remains at position 0: ".*"$' ,
484
+ r'^at position 0: time data ".*" doesn\'t match format ".*"$' ,
485
+ r'^at position 0: unconverted data remains : ".*"$' ,
486
486
]
487
487
)
488
488
with pytest .raises (ValueError , match = msg ):
@@ -859,7 +859,7 @@ def test_to_datetime_dt64s_and_str(self, arg, format):
859
859
"dt" , [np .datetime64 ("1000-01-01" ), np .datetime64 ("5000-01-02" )]
860
860
)
861
861
def test_to_datetime_dt64s_out_of_bounds (self , cache , dt ):
862
- msg = "Out of bounds .* present at position 0 "
862
+ msg = "^at position 0: Out of bounds nanosecond timestamp: .*$ "
863
863
with pytest .raises (OutOfBoundsDatetime , match = msg ):
864
864
to_datetime (dt , errors = "raise" )
865
865
@@ -1098,7 +1098,7 @@ def test_datetime_bool_arrays_mixed(self, cache):
1098
1098
to_datetime ([False , datetime .today ()], cache = cache )
1099
1099
with pytest .raises (
1100
1100
ValueError ,
1101
- match = r'^time data "True" at position 1 doesn\'t match format "%Y%m%d"$' ,
1101
+ match = r'^at position 1: time data "True" doesn\'t match format "%Y%m%d"$' ,
1102
1102
):
1103
1103
to_datetime (["20130101" , True ], cache = cache )
1104
1104
tm .assert_index_equal (
@@ -1139,10 +1139,10 @@ def test_datetime_invalid_scalar(self, value, format, warning):
1139
1139
1140
1140
msg = "|" .join (
1141
1141
[
1142
- r'^time data "a" at position 0 doesn\'t match format "%H:%M:%S"$' ,
1143
- r'^Given date string "a" not likely a datetime present at position 0 $' ,
1144
- r'^unconverted data remains at position 0: "9"$' ,
1145
- r"^second must be in 0..59: 00:01:99 present at position 0 $" ,
1142
+ r'^at position 0: time data "a" doesn\'t match format "%H:%M:%S"$' ,
1143
+ r'^at position 0: Given date string "a" not likely a datetime$' ,
1144
+ r'^at position 0: unconverted data remains : "9"$' ,
1145
+ r"^at position 0: second must be in 0..59: 00:01:99$" ,
1146
1146
]
1147
1147
)
1148
1148
with pytest .raises (ValueError , match = msg ):
@@ -1164,11 +1164,11 @@ def test_datetime_outofbounds_scalar(self, value, format, warning):
1164
1164
assert res is NaT
1165
1165
1166
1166
if format is not None :
1167
- msg = r'^time data ".*" at position 0 doesn\'t match format ".*"$'
1167
+ msg = r'^at position 0: time data ".*" doesn\'t match format ".*"$'
1168
1168
with pytest .raises (ValueError , match = msg ):
1169
1169
to_datetime (value , errors = "raise" , format = format )
1170
1170
else :
1171
- msg = "Out of bounds .* present at position 0 "
1171
+ msg = "^at position 0: Out of bounds .*$ "
1172
1172
with pytest .raises (
1173
1173
OutOfBoundsDatetime , match = msg
1174
1174
), tm .assert_produces_warning (warning , match = "Could not infer format" ):
@@ -1190,10 +1190,10 @@ def test_datetime_invalid_index(self, values, format, warning):
1190
1190
1191
1191
msg = "|" .join (
1192
1192
[
1193
- r'^Given date string "a" not likely a datetime present at position 0 $' ,
1194
- r'^time data "a" at position 0 doesn\'t match format "%H:%M:%S"$' ,
1195
- r'^unconverted data remains at position 0: "9"$' ,
1196
- r"^second must be in 0..59: 00:01:99 present at position 0 $" ,
1193
+ r'^at position 0: Given date string "a" not likely a datetime$' ,
1194
+ r'^at position 0: time data "a" doesn\'t match format "%H:%M:%S"$' ,
1195
+ r'^at position 0: unconverted data remains : "9"$' ,
1196
+ r"^at position 0: second must be in 0..59: 00:01:99$" ,
1197
1197
]
1198
1198
)
1199
1199
with pytest .raises (ValueError , match = msg ):
@@ -1373,7 +1373,7 @@ def test_to_datetime_malformed_raise(self):
1373
1373
ts_strings = ["200622-12-31" , "111111-24-11" ]
1374
1374
with pytest .raises (
1375
1375
ValueError ,
1376
- match = r"^hour must be in 0\.\.23: 111111-24-11 present at position 1 $" ,
1376
+ match = r"^at position 1: hour must be in 0\.\.23: 111111-24-11$" ,
1377
1377
):
1378
1378
with tm .assert_produces_warning (
1379
1379
UserWarning , match = "Could not infer format"
@@ -1814,7 +1814,7 @@ def test_dataframe_coerce(self, cache):
1814
1814
df2 = DataFrame ({"year" : [2015 , 2016 ], "month" : [2 , 20 ], "day" : [4 , 5 ]})
1815
1815
1816
1816
msg = (
1817
- r'^cannot assemble the datetimes: time data ".+" at position 1 doesn\'t '
1817
+ r'^cannot assemble the datetimes: at position 1: time data ".+" doesn\'t '
1818
1818
r'match format "%Y%m%d"$'
1819
1819
)
1820
1820
with pytest .raises (ValueError , match = msg ):
@@ -1892,8 +1892,8 @@ def test_dataframe_float(self, cache):
1892
1892
# float
1893
1893
df = DataFrame ({"year" : [2000 , 2001 ], "month" : [1.5 , 1 ], "day" : [1 , 1 ]})
1894
1894
msg = (
1895
- r"^cannot assemble the datetimes: unconverted data remains at position "
1896
- r'0: "1"$'
1895
+ r"^cannot assemble the datetimes: at position 0: unconverted data remains: "
1896
+ r'"1"$'
1897
1897
)
1898
1898
with pytest .raises (ValueError , match = msg ):
1899
1899
to_datetime (df , cache = cache )
@@ -1915,7 +1915,7 @@ def test_to_datetime_barely_out_of_bounds(self):
1915
1915
# in an in-bounds datetime
1916
1916
arr = np .array (["2262-04-11 23:47:16.854775808" ], dtype = object )
1917
1917
1918
- msg = "Out of bounds .* present at position 0 "
1918
+ msg = "^at position 0: Out of bounds .*$ "
1919
1919
with pytest .raises (OutOfBoundsDatetime , match = msg ):
1920
1920
with tm .assert_produces_warning (
1921
1921
UserWarning , match = "Could not infer format"
@@ -1954,7 +1954,7 @@ def test_to_datetime_iso8601_fails(self, input, format, exact):
1954
1954
with pytest .raises (
1955
1955
ValueError ,
1956
1956
match = (
1957
- rf"time data \"{ input } \" at position 0 doesn't match format "
1957
+ rf"at position 0: time data \"{ input } \" doesn't match format "
1958
1958
rf"\" { format } \""
1959
1959
),
1960
1960
):
@@ -1976,7 +1976,7 @@ def test_to_datetime_iso8601_exact_fails(self, input, format):
1976
1976
with pytest .raises (
1977
1977
ValueError ,
1978
1978
match = (
1979
- rf"time data \"{ input } \" at position 0 doesn't match format "
1979
+ rf"at position 0: time data \"{ input } \" doesn't match format "
1980
1980
rf"\" { format } \""
1981
1981
),
1982
1982
):
@@ -2015,7 +2015,7 @@ def test_to_datetime_iso8601_separator(self, input, format):
2015
2015
with pytest .raises (
2016
2016
ValueError ,
2017
2017
match = (
2018
- rf"time data \"{ input } \" at position 0 doesn\'t match format "
2018
+ rf"at position 0: time data \"{ input } \" doesn\'t match format "
2019
2019
rf"\" { format } \""
2020
2020
),
2021
2021
):
@@ -2084,7 +2084,7 @@ def test_to_datetime_on_datetime64_series(self, cache):
2084
2084
def test_to_datetime_with_space_in_series (self , cache ):
2085
2085
# GH 6428
2086
2086
ser = Series (["10/18/2006" , "10/18/2008" , " " ])
2087
- msg = r'^time data " " at position 2 doesn\'t match format "%m/%d/%Y"$'
2087
+ msg = r'^at position 2: time data " " doesn\'t match format "%m/%d/%Y"$'
2088
2088
with pytest .raises (ValueError , match = msg ):
2089
2089
to_datetime (ser , errors = "raise" , cache = cache )
2090
2090
result_coerce = to_datetime (ser , errors = "coerce" , cache = cache )
@@ -2355,7 +2355,7 @@ def test_dayfirst_warnings_invalid_input(self):
2355
2355
with pytest .raises (
2356
2356
ValueError ,
2357
2357
match = (
2358
- r'^time data "03/30/2011" at position 1 doesn\'t match format '
2358
+ r'^at position 1: time data "03/30/2011" doesn\'t match format '
2359
2359
r'"%d/%m/%Y"$'
2360
2360
),
2361
2361
):
@@ -2426,7 +2426,7 @@ def test_to_datetime_inconsistent_format(self, cache):
2426
2426
data = ["01/01/2011 00:00:00" , "01-02-2011 00:00:00" , "2011-01-03T00:00:00" ]
2427
2427
ser = Series (np .array (data ))
2428
2428
msg = (
2429
- r'^time data "01-02-2011 00:00:00" at position 1 doesn\'t match format '
2429
+ r'^at position 1: time data "01-02-2011 00:00:00" doesn\'t match format '
2430
2430
r'"%m/%d/%Y %H:%M:%S"$'
2431
2431
)
2432
2432
with pytest .raises (ValueError , match = msg ):
@@ -2552,7 +2552,7 @@ def test_day_not_in_month_raise(self, cache):
2552
2552
2553
2553
@pytest .mark .parametrize ("arg" , ["2015-02-29" , "2015-02-32" , "2015-04-31" ])
2554
2554
def test_day_not_in_month_raise_value (self , cache , arg ):
2555
- msg = f'time data "{ arg } " at position 0 doesn\' t match format "%Y-%m-%d"'
2555
+ msg = f'at position 0: time data "{ arg } " doesn\' t match format "%Y-%m-%d"'
2556
2556
with pytest .raises (ValueError , match = msg ):
2557
2557
to_datetime (arg , errors = "raise" , format = "%Y-%m-%d" , cache = cache )
2558
2558
@@ -2934,7 +2934,7 @@ def test_invalid_origins_tzinfo(self):
2934
2934
def test_incorrect_value_exception (self ):
2935
2935
# GH47495
2936
2936
with pytest .raises (
2937
- ValueError , match = "Unknown string format: yesterday present at position 1 "
2937
+ ValueError , match = "at position 1: Unknown string format: yesterday"
2938
2938
):
2939
2939
with tm .assert_produces_warning (
2940
2940
UserWarning , match = "Could not infer format"
@@ -2952,8 +2952,7 @@ def test_incorrect_value_exception(self):
2952
2952
def test_to_datetime_out_of_bounds_with_format_arg (self , format , warning ):
2953
2953
# see gh-23830
2954
2954
msg = (
2955
- r"^Out of bounds nanosecond timestamp: 2417-10-10 00:00:00 "
2956
- r"present at position 0$"
2955
+ r"^at position 0: Out of bounds nanosecond timestamp: 2417-10-10 00:00:00$"
2957
2956
)
2958
2957
with pytest .raises (OutOfBoundsDatetime , match = msg ):
2959
2958
with tm .assert_produces_warning (warning , match = "Could not infer format" ):
0 commit comments