@@ -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'^time data ".*" doesn\'t match format ".*", at position 0 $' ,
485
+ r'^unconverted data remains: ".*", at position 0 $' ,
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 = "^ Out of bounds nanosecond timestamp: .*, at position 0$ "
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'^time data "True" doesn\'t match format "%Y%m%d", at position 1 $' ,
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'^time data "a" doesn\'t match format "%H:%M:%S", at position 0 $' ,
1143
+ r'^Given date string "a" not likely a datetime, at position 0$' ,
1144
+ r'^unconverted data remains: "9", at position 0$' ,
1145
+ r"^second must be in 0..59: 00:01:99, at position 0$" ,
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'^time data ".*" doesn\'t match format ".*", at position 0 $'
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 = "^ Out of bounds .*, at position 0$ "
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'^Given date string "a" not likely a datetime, at position 0$' ,
1194
+ r'^time data "a" doesn\'t match format "%H:%M:%S", at position 0 $' ,
1195
+ r'^unconverted data remains: "9", at position 0$' ,
1196
+ r"^second must be in 0..59: 00:01:99, at position 0$" ,
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"^hour must be in 0\.\.23: 111111-24-11, at position 1$" ,
1377
1377
):
1378
1378
with tm .assert_produces_warning (
1379
1379
UserWarning , match = "Could not infer format"
@@ -1814,8 +1814,8 @@ 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 '
1818
- r'match format "%Y%m%d"$'
1817
+ r'^cannot assemble the datetimes: time data ".+" doesn\'t '
1818
+ r'match format "%Y%m%d", at position 1 $'
1819
1819
)
1820
1820
with pytest .raises (ValueError , match = msg ):
1821
1821
to_datetime (df2 , cache = cache )
@@ -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: unconverted data remains: "
1896
+ r'"1", at position 0 $'
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 = "^ Out of bounds nanosecond timestamp: .*, at position 0"
1919
1919
with pytest .raises (OutOfBoundsDatetime , match = msg ):
1920
1920
with tm .assert_produces_warning (
1921
1921
UserWarning , match = "Could not infer format"
@@ -1954,8 +1954,8 @@ 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 "
1958
- rf"\" { format } \""
1957
+ rf"time data \"{ input } \" doesn't match format "
1958
+ rf"\" { format } \", at position 0 "
1959
1959
),
1960
1960
):
1961
1961
to_datetime (input , format = format , exact = exact )
@@ -1976,8 +1976,8 @@ 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 "
1980
- rf"\" { format } \""
1979
+ rf"time data \"{ input } \" doesn't match format "
1980
+ rf"\" { format } \", at position 0 "
1981
1981
),
1982
1982
):
1983
1983
to_datetime (input , format = format )
@@ -2015,8 +2015,8 @@ 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 "
2019
- rf"\" { format } \""
2018
+ rf"time data \"{ input } \" doesn\'t match format "
2019
+ rf"\" { format } \", at position 0 "
2020
2020
),
2021
2021
):
2022
2022
to_datetime (input , format = format )
@@ -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'^time data " " doesn\'t match format "%m/%d/%Y", at position 2 $'
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,8 +2355,8 @@ 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 '
2359
- r'"%d/%m/%Y"$'
2358
+ r'^time data "03/30/2011" doesn\'t match format '
2359
+ r'"%d/%m/%Y", at position 1 $'
2360
2360
),
2361
2361
):
2362
2362
to_datetime (arr , dayfirst = True )
@@ -2426,8 +2426,8 @@ 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 '
2430
- r'"%m/%d/%Y %H:%M:%S"$'
2429
+ r'^time data "01-02-2011 00:00:00" doesn\'t match format '
2430
+ r'"%m/%d/%Y %H:%M:%S", at position 1 $'
2431
2431
)
2432
2432
with pytest .raises (ValueError , match = msg ):
2433
2433
to_datetime (ser , cache = cache )
@@ -2550,11 +2550,49 @@ def test_day_not_in_month_raise(self, cache):
2550
2550
):
2551
2551
to_datetime ("2015-02-29" , errors = "raise" , cache = cache )
2552
2552
2553
- @pytest .mark .parametrize ("arg" , ["2015-02-29" , "2015-02-32" , "2015-04-31" ])
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"'
2553
+ @pytest .mark .parametrize (
2554
+ "arg, format, msg" ,
2555
+ [
2556
+ (
2557
+ "2015-02-29" ,
2558
+ "%Y-%m-%d" ,
2559
+ '^time data "2015-02-29" doesn\' t match format "%Y-%m-%d", '
2560
+ "at position 0$" ,
2561
+ ),
2562
+ (
2563
+ "2015-29-02" ,
2564
+ "%Y-%d-%m" ,
2565
+ "^day is out of range for month, at position 0$" ,
2566
+ ),
2567
+ (
2568
+ "2015-02-32" ,
2569
+ "%Y-%m-%d" ,
2570
+ '^time data "2015-02-32" doesn\' t match format "%Y-%m-%d", '
2571
+ "at position 0$" ,
2572
+ ),
2573
+ (
2574
+ "2015-32-02" ,
2575
+ "%Y-%d-%m" ,
2576
+ '^time data "2015-32-02" doesn\' t match format "%Y-%d-%m", '
2577
+ "at position 0$" ,
2578
+ ),
2579
+ (
2580
+ "2015-04-31" ,
2581
+ "%Y-%m-%d" ,
2582
+ '^time data "2015-04-31" doesn\' t match format "%Y-%m-%d", '
2583
+ "at position 0$" ,
2584
+ ),
2585
+ (
2586
+ "2015-31-04" ,
2587
+ "%Y-%d-%m" ,
2588
+ "^day is out of range for month, at position 0$" ,
2589
+ ),
2590
+ ],
2591
+ )
2592
+ def test_day_not_in_month_raise_value (self , cache , arg , format , msg ):
2593
+ # https://github.com/pandas-dev/pandas/issues/50462
2556
2594
with pytest .raises (ValueError , match = msg ):
2557
- to_datetime (arg , errors = "raise" , format = "%Y-%m-%d" , cache = cache )
2595
+ to_datetime (arg , errors = "raise" , format = format , cache = cache )
2558
2596
2559
2597
@pytest .mark .parametrize (
2560
2598
"expected, format, warning" ,
@@ -2934,7 +2972,7 @@ def test_invalid_origins_tzinfo(self):
2934
2972
def test_incorrect_value_exception (self ):
2935
2973
# GH47495
2936
2974
with pytest .raises (
2937
- ValueError , match = "Unknown string format: yesterday present at position 1"
2975
+ ValueError , match = "Unknown string format: yesterday, at position 1"
2938
2976
):
2939
2977
with tm .assert_produces_warning (
2940
2978
UserWarning , match = "Could not infer format"
@@ -2952,8 +2990,7 @@ def test_incorrect_value_exception(self):
2952
2990
def test_to_datetime_out_of_bounds_with_format_arg (self , format , warning ):
2953
2991
# see gh-23830
2954
2992
msg = (
2955
- r"^Out of bounds nanosecond timestamp: 2417-10-10 00:00:00 "
2956
- r"present at position 0$"
2993
+ r"^Out of bounds nanosecond timestamp: 2417-10-10 00:00:00, at position 0$"
2957
2994
)
2958
2995
with pytest .raises (OutOfBoundsDatetime , match = msg ):
2959
2996
with tm .assert_produces_warning (warning , match = "Could not infer format" ):
0 commit comments