@@ -480,8 +480,8 @@ def test_to_datetime_parse_timezone_malformed(self, offset):
480
480
481
481
msg = "|" .join (
482
482
[
483
- r'^time data ".*" at position 0 doesn\'t match format ".*"$' ,
484
- r'^unconverted data remains at position 0 : ".*"$' ,
483
+ r'^time data ".*" doesn\'t match format ".*", at position 0 $' ,
484
+ r'^unconverted data remains: ".*", at position 0 $' ,
485
485
]
486
486
)
487
487
with pytest .raises (ValueError , match = msg ):
@@ -858,7 +858,7 @@ def test_to_datetime_dt64s_and_str(self, arg, format):
858
858
"dt" , [np .datetime64 ("1000-01-01" ), np .datetime64 ("5000-01-02" )]
859
859
)
860
860
def test_to_datetime_dt64s_out_of_bounds (self , cache , dt ):
861
- msg = "Out of bounds .* present at position 0"
861
+ msg = "^ Out of bounds nanosecond timestamp: .*, at position 0$ "
862
862
with pytest .raises (OutOfBoundsDatetime , match = msg ):
863
863
to_datetime (dt , errors = "raise" )
864
864
@@ -1097,7 +1097,7 @@ def test_datetime_bool_arrays_mixed(self, cache):
1097
1097
to_datetime ([False , datetime .today ()], cache = cache )
1098
1098
with pytest .raises (
1099
1099
ValueError ,
1100
- match = r'^time data "True" at position 1 doesn\'t match format "%Y%m%d"$' ,
1100
+ match = r'^time data "True" doesn\'t match format "%Y%m%d", at position 1 $' ,
1101
1101
):
1102
1102
to_datetime (["20130101" , True ], cache = cache )
1103
1103
tm .assert_index_equal (
@@ -1138,10 +1138,10 @@ def test_datetime_invalid_scalar(self, value, format, warning):
1138
1138
1139
1139
msg = "|" .join (
1140
1140
[
1141
- r'^time data "a" at position 0 doesn\'t match format "%H:%M:%S"$' ,
1142
- r'^Given date string "a" not likely a datetime present at position 0$' ,
1143
- r'^unconverted data remains at position 0: "9" $' ,
1144
- r"^second must be in 0..59: 00:01:99 present at position 0$" ,
1141
+ r'^time data "a" doesn\'t match format "%H:%M:%S", at position 0 $' ,
1142
+ r'^Given date string "a" not likely a datetime, at position 0$' ,
1143
+ r'^unconverted data remains: "9", at position 0$' ,
1144
+ r"^second must be in 0..59: 00:01:99, at position 0$" ,
1145
1145
]
1146
1146
)
1147
1147
with pytest .raises (ValueError , match = msg ):
@@ -1163,11 +1163,11 @@ def test_datetime_outofbounds_scalar(self, value, format, warning):
1163
1163
assert res is NaT
1164
1164
1165
1165
if format is not None :
1166
- msg = r'^time data ".*" at position 0 doesn\'t match format ".*"$'
1166
+ msg = r'^time data ".*" doesn\'t match format ".*", at position 0 $'
1167
1167
with pytest .raises (ValueError , match = msg ):
1168
1168
to_datetime (value , errors = "raise" , format = format )
1169
1169
else :
1170
- msg = "Out of bounds .* present at position 0"
1170
+ msg = "^ Out of bounds .*, at position 0$ "
1171
1171
with pytest .raises (
1172
1172
OutOfBoundsDatetime , match = msg
1173
1173
), tm .assert_produces_warning (warning , match = "Could not infer format" ):
@@ -1189,10 +1189,10 @@ def test_datetime_invalid_index(self, values, format, warning):
1189
1189
1190
1190
msg = "|" .join (
1191
1191
[
1192
- r'^Given date string "a" not likely a datetime present at position 0$' ,
1193
- r'^time data "a" at position 0 doesn\'t match format "%H:%M:%S"$' ,
1194
- r'^unconverted data remains at position 0: "9" $' ,
1195
- r"^second must be in 0..59: 00:01:99 present at position 0$" ,
1192
+ r'^Given date string "a" not likely a datetime, at position 0$' ,
1193
+ r'^time data "a" doesn\'t match format "%H:%M:%S", at position 0 $' ,
1194
+ r'^unconverted data remains: "9", at position 0$' ,
1195
+ r"^second must be in 0..59: 00:01:99, at position 0$" ,
1196
1196
]
1197
1197
)
1198
1198
with pytest .raises (ValueError , match = msg ):
@@ -1372,7 +1372,7 @@ def test_to_datetime_malformed_raise(self):
1372
1372
ts_strings = ["200622-12-31" , "111111-24-11" ]
1373
1373
with pytest .raises (
1374
1374
ValueError ,
1375
- match = r"^hour must be in 0\.\.23: 111111-24-11 present at position 1$" ,
1375
+ match = r"^hour must be in 0\.\.23: 111111-24-11, at position 1$" ,
1376
1376
):
1377
1377
with tm .assert_produces_warning (
1378
1378
UserWarning , match = "Could not infer format"
@@ -1845,8 +1845,8 @@ def test_dataframe_coerce(self, cache):
1845
1845
df2 = DataFrame ({"year" : [2015 , 2016 ], "month" : [2 , 20 ], "day" : [4 , 5 ]})
1846
1846
1847
1847
msg = (
1848
- r'^cannot assemble the datetimes: time data ".+" at position 1 doesn\'t '
1849
- r'match format "%Y%m%d"$'
1848
+ r'^cannot assemble the datetimes: time data ".+" doesn\'t '
1849
+ r'match format "%Y%m%d", at position 1 $'
1850
1850
)
1851
1851
with pytest .raises (ValueError , match = msg ):
1852
1852
to_datetime (df2 , cache = cache )
@@ -1923,8 +1923,8 @@ def test_dataframe_float(self, cache):
1923
1923
# float
1924
1924
df = DataFrame ({"year" : [2000 , 2001 ], "month" : [1.5 , 1 ], "day" : [1 , 1 ]})
1925
1925
msg = (
1926
- r"^cannot assemble the datetimes: unconverted data remains at position "
1927
- r'0: "1"$'
1926
+ r"^cannot assemble the datetimes: unconverted data remains: "
1927
+ r'"1", at position 0 $'
1928
1928
)
1929
1929
with pytest .raises (ValueError , match = msg ):
1930
1930
to_datetime (df , cache = cache )
@@ -1946,7 +1946,7 @@ def test_to_datetime_barely_out_of_bounds(self):
1946
1946
# in an in-bounds datetime
1947
1947
arr = np .array (["2262-04-11 23:47:16.854775808" ], dtype = object )
1948
1948
1949
- msg = "Out of bounds .* present at position 0"
1949
+ msg = "^ Out of bounds nanosecond timestamp: .*, at position 0"
1950
1950
with pytest .raises (OutOfBoundsDatetime , match = msg ):
1951
1951
with tm .assert_produces_warning (
1952
1952
UserWarning , match = "Could not infer format"
@@ -1985,8 +1985,8 @@ def test_to_datetime_iso8601_fails(self, input, format, exact):
1985
1985
with pytest .raises (
1986
1986
ValueError ,
1987
1987
match = (
1988
- rf"time data \"{ input } \" at position 0 doesn't match format "
1989
- rf"\" { format } \""
1988
+ rf"time data \"{ input } \" doesn't match format "
1989
+ rf"\" { format } \", at position 0 "
1990
1990
),
1991
1991
):
1992
1992
to_datetime (input , format = format , exact = exact )
@@ -2007,8 +2007,8 @@ def test_to_datetime_iso8601_exact_fails(self, input, format):
2007
2007
with pytest .raises (
2008
2008
ValueError ,
2009
2009
match = (
2010
- rf"time data \"{ input } \" at position 0 doesn't match format "
2011
- rf"\" { format } \""
2010
+ rf"time data \"{ input } \" doesn't match format "
2011
+ rf"\" { format } \", at position 0 "
2012
2012
),
2013
2013
):
2014
2014
to_datetime (input , format = format )
@@ -2046,8 +2046,8 @@ def test_to_datetime_iso8601_separator(self, input, format):
2046
2046
with pytest .raises (
2047
2047
ValueError ,
2048
2048
match = (
2049
- rf"time data \"{ input } \" at position 0 doesn\'t match format "
2050
- rf"\" { format } \""
2049
+ rf"time data \"{ input } \" doesn\'t match format "
2050
+ rf"\" { format } \", at position 0 "
2051
2051
),
2052
2052
):
2053
2053
to_datetime (input , format = format )
@@ -2115,7 +2115,7 @@ def test_to_datetime_on_datetime64_series(self, cache):
2115
2115
def test_to_datetime_with_space_in_series (self , cache ):
2116
2116
# GH 6428
2117
2117
ser = Series (["10/18/2006" , "10/18/2008" , " " ])
2118
- msg = r'^time data " " at position 2 doesn\'t match format "%m/%d/%Y"$'
2118
+ msg = r'^time data " " doesn\'t match format "%m/%d/%Y", at position 2 $'
2119
2119
with pytest .raises (ValueError , match = msg ):
2120
2120
to_datetime (ser , errors = "raise" , cache = cache )
2121
2121
result_coerce = to_datetime (ser , errors = "coerce" , cache = cache )
@@ -2386,8 +2386,8 @@ def test_dayfirst_warnings_invalid_input(self):
2386
2386
with pytest .raises (
2387
2387
ValueError ,
2388
2388
match = (
2389
- r'^time data "03/30/2011" at position 1 doesn\'t match format '
2390
- r'"%d/%m/%Y"$'
2389
+ r'^time data "03/30/2011" doesn\'t match format '
2390
+ r'"%d/%m/%Y", at position 1 $'
2391
2391
),
2392
2392
):
2393
2393
to_datetime (arr , dayfirst = True )
@@ -2457,8 +2457,8 @@ def test_to_datetime_inconsistent_format(self, cache):
2457
2457
data = ["01/01/2011 00:00:00" , "01-02-2011 00:00:00" , "2011-01-03T00:00:00" ]
2458
2458
ser = Series (np .array (data ))
2459
2459
msg = (
2460
- r'^time data "01-02-2011 00:00:00" at position 1 doesn\'t match format '
2461
- r'"%m/%d/%Y %H:%M:%S"$'
2460
+ r'^time data "01-02-2011 00:00:00" doesn\'t match format '
2461
+ r'"%m/%d/%Y %H:%M:%S", at position 1 $'
2462
2462
)
2463
2463
with pytest .raises (ValueError , match = msg ):
2464
2464
to_datetime (ser , cache = cache )
@@ -2581,11 +2581,49 @@ def test_day_not_in_month_raise(self, cache):
2581
2581
):
2582
2582
to_datetime ("2015-02-29" , errors = "raise" , cache = cache )
2583
2583
2584
- @pytest .mark .parametrize ("arg" , ["2015-02-29" , "2015-02-32" , "2015-04-31" ])
2585
- def test_day_not_in_month_raise_value (self , cache , arg ):
2586
- msg = f'time data "{ arg } " at position 0 doesn\' t match format "%Y-%m-%d"'
2584
+ @pytest .mark .parametrize (
2585
+ "arg, format, msg" ,
2586
+ [
2587
+ (
2588
+ "2015-02-29" ,
2589
+ "%Y-%m-%d" ,
2590
+ '^time data "2015-02-29" doesn\' t match format "%Y-%m-%d", '
2591
+ "at position 0$" ,
2592
+ ),
2593
+ (
2594
+ "2015-29-02" ,
2595
+ "%Y-%d-%m" ,
2596
+ "^day is out of range for month, at position 0$" ,
2597
+ ),
2598
+ (
2599
+ "2015-02-32" ,
2600
+ "%Y-%m-%d" ,
2601
+ '^time data "2015-02-32" doesn\' t match format "%Y-%m-%d", '
2602
+ "at position 0$" ,
2603
+ ),
2604
+ (
2605
+ "2015-32-02" ,
2606
+ "%Y-%d-%m" ,
2607
+ '^time data "2015-32-02" doesn\' t match format "%Y-%d-%m", '
2608
+ "at position 0$" ,
2609
+ ),
2610
+ (
2611
+ "2015-04-31" ,
2612
+ "%Y-%m-%d" ,
2613
+ '^time data "2015-04-31" doesn\' t match format "%Y-%m-%d", '
2614
+ "at position 0$" ,
2615
+ ),
2616
+ (
2617
+ "2015-31-04" ,
2618
+ "%Y-%d-%m" ,
2619
+ "^day is out of range for month, at position 0$" ,
2620
+ ),
2621
+ ],
2622
+ )
2623
+ def test_day_not_in_month_raise_value (self , cache , arg , format , msg ):
2624
+ # https://github.com/pandas-dev/pandas/issues/50462
2587
2625
with pytest .raises (ValueError , match = msg ):
2588
- to_datetime (arg , errors = "raise" , format = "%Y-%m-%d" , cache = cache )
2626
+ to_datetime (arg , errors = "raise" , format = format , cache = cache )
2589
2627
2590
2628
@pytest .mark .parametrize (
2591
2629
"expected, format, warning" ,
@@ -2965,7 +3003,7 @@ def test_invalid_origins_tzinfo(self):
2965
3003
def test_incorrect_value_exception (self ):
2966
3004
# GH47495
2967
3005
with pytest .raises (
2968
- ValueError , match = "Unknown string format: yesterday present at position 1"
3006
+ ValueError , match = "Unknown string format: yesterday, at position 1"
2969
3007
):
2970
3008
with tm .assert_produces_warning (
2971
3009
UserWarning , match = "Could not infer format"
@@ -2983,8 +3021,7 @@ def test_incorrect_value_exception(self):
2983
3021
def test_to_datetime_out_of_bounds_with_format_arg (self , format , warning ):
2984
3022
# see gh-23830
2985
3023
msg = (
2986
- r"^Out of bounds nanosecond timestamp: 2417-10-10 00:00:00 "
2987
- r"present at position 0$"
3024
+ r"^Out of bounds nanosecond timestamp: 2417-10-10 00:00:00, at position 0$"
2988
3025
)
2989
3026
with pytest .raises (OutOfBoundsDatetime , match = msg ):
2990
3027
with tm .assert_produces_warning (warning , match = "Could not infer format" ):
0 commit comments