@@ -133,8 +133,7 @@ def test_to_datetime_format_YYYYMMDD_with_nat(self, cache):
133
133
with pytest .raises (
134
134
ValueError ,
135
135
match = (
136
- 'unconverted data remains when parsing with format "%Y%m%d": ".0", '
137
- "at position 0"
136
+ 'unconverted data remains when parsing with format "%Y%m%d": ".0". '
138
137
),
139
138
):
140
139
# https://github.com/pandas-dev/pandas/issues/50051
@@ -514,10 +513,9 @@ def test_to_datetime_parse_timezone_malformed(self, offset):
514
513
515
514
msg = "|" .join (
516
515
[
517
- r'^time data ".*" doesn\'t match format ".*", at position 0. '
516
+ r'^time data ".*" doesn\'t match format ".*". ' f"{ PARSING_ERR_MSG } $" ,
517
+ r'^unconverted data remains when parsing with format ".*": ".*". '
518
518
f"{ PARSING_ERR_MSG } $" ,
519
- r'^unconverted data remains when parsing with format ".*": ".*", '
520
- f"at position 0. { PARSING_ERR_MSG } $" ,
521
519
]
522
520
)
523
521
with pytest .raises (ValueError , match = msg ):
@@ -539,7 +537,7 @@ def test_to_datetime_overflow(self):
539
537
# TODO: Timestamp raises ValueError("could not convert string to Timestamp")
540
538
# can we make these more consistent?
541
539
arg = "08335394550"
542
- msg = 'Parsing "08335394550" to datetime overflows, at position 0 '
540
+ msg = 'Parsing "08335394550" to datetime overflows'
543
541
with pytest .raises (OutOfBoundsDatetime , match = msg ):
544
542
to_datetime (arg )
545
543
@@ -1309,8 +1307,8 @@ def test_datetime_bool_arrays_mixed(self, cache):
1309
1307
with pytest .raises (
1310
1308
ValueError ,
1311
1309
match = (
1312
- r'^time data "True" doesn\'t match format "%Y%m%d", '
1313
- f"at position 1. { PARSING_ERR_MSG } $"
1310
+ r'^time data "True" doesn\'t match format "%Y%m%d". '
1311
+ f"{ PARSING_ERR_MSG } $"
1314
1312
),
1315
1313
):
1316
1314
to_datetime (["20130101" , True ], cache = cache )
@@ -1345,12 +1343,12 @@ def test_datetime_invalid_scalar(self, value, format):
1345
1343
1346
1344
msg = "|" .join (
1347
1345
[
1348
- r'^time data "a" doesn\'t match format "%H:%M:%S", at position 0 . '
1346
+ r'^time data "a" doesn\'t match format "%H:%M:%S". '
1349
1347
f"{ PARSING_ERR_MSG } $" ,
1350
- r'^Given date string "a" not likely a datetime, at position 0 $' ,
1351
- r'^unconverted data remains when parsing with format "%H:%M:%S": "9", '
1352
- f"at position 0. { PARSING_ERR_MSG } $" ,
1353
- r"^second must be in 0..59: 00:01:99, at position 0 $" ,
1348
+ r'^Given date string "a" not likely a datetime$' ,
1349
+ r'^unconverted data remains when parsing with format "%H:%M:%S": "9". '
1350
+ f"{ PARSING_ERR_MSG } $" ,
1351
+ r"^second must be in 0..59: 00:01:99$" ,
1354
1352
]
1355
1353
)
1356
1354
with pytest .raises (ValueError , match = msg ):
@@ -1368,7 +1366,7 @@ def test_datetime_outofbounds_scalar(self, value, format):
1368
1366
assert res is NaT
1369
1367
1370
1368
if format is not None :
1371
- msg = r'^time data ".*" doesn\'t match format ".*", at position 0. '
1369
+ msg = r'^time data ".*" doesn\'t match format ".*"'
1372
1370
with pytest .raises (ValueError , match = msg ):
1373
1371
to_datetime (value , errors = "raise" , format = format )
1374
1372
else :
@@ -1397,12 +1395,12 @@ def test_datetime_invalid_index(self, values, format):
1397
1395
1398
1396
msg = "|" .join (
1399
1397
[
1400
- r'^Given date string "a" not likely a datetime, at position 0$' ,
1401
- r'^time data "a" doesn\'t match format "%H:%M:%S", at position 0. '
1398
+ r'^Given date string "a" not likely a datetime$' ,
1399
+ r'^time data "a" doesn\'t match format "%H:%M:%S". '
1400
+ f"{ PARSING_ERR_MSG } $" ,
1401
+ r'^unconverted data remains when parsing with format "%H:%M:%S": "9". '
1402
1402
f"{ PARSING_ERR_MSG } $" ,
1403
- r'^unconverted data remains when parsing with format "%H:%M:%S": "9", '
1404
- f"at position 0. { PARSING_ERR_MSG } $" ,
1405
- r"^second must be in 0..59: 00:01:99, at position 0$" ,
1403
+ r"^second must be in 0..59: 00:01:99$" ,
1406
1404
]
1407
1405
)
1408
1406
with pytest .raises (ValueError , match = msg ):
@@ -1582,8 +1580,7 @@ def test_to_datetime_malformed_raise(self):
1582
1580
ts_strings = ["200622-12-31" , "111111-24-11" ]
1583
1581
msg = (
1584
1582
'Parsed string "200622-12-31" gives an invalid tzoffset, which must '
1585
- r"be between -timedelta\(hours=24\) and timedelta\(hours=24\), "
1586
- "at position 0"
1583
+ r"be between -timedelta\(hours=24\) and timedelta\(hours=24\)"
1587
1584
)
1588
1585
with pytest .raises (
1589
1586
ValueError ,
@@ -1748,7 +1745,7 @@ def test_to_datetime_month_or_year_unit_non_round_float(self, cache, unit):
1748
1745
with pytest .raises (ValueError , match = msg ):
1749
1746
to_datetime (np .array ([1.5 ]), unit = unit , errors = "raise" )
1750
1747
1751
- msg = r"Given date string \"1.5\" not likely a datetime, at position 0 "
1748
+ msg = r"Given date string \"1.5\" not likely a datetime"
1752
1749
with pytest .raises (ValueError , match = msg ):
1753
1750
to_datetime (["1.5" ], unit = unit , errors = "raise" )
1754
1751
@@ -1802,7 +1799,7 @@ def test_unit_array_mixed_nans_large_int(self, cache):
1802
1799
def test_to_datetime_invalid_str_not_out_of_bounds_valuerror (self , cache ):
1803
1800
# if we have a string, then we raise a ValueError
1804
1801
# and NOT an OutOfBoundsDatetime
1805
- msg = "Unknown datetime string format, unable to parse: foo, at position 0 "
1802
+ msg = "Unknown datetime string format, unable to parse: foo"
1806
1803
with pytest .raises (ValueError , match = msg ):
1807
1804
to_datetime ("foo" , errors = "raise" , unit = "s" , cache = cache )
1808
1805
@@ -1938,12 +1935,9 @@ def test_to_datetime_unit_na_values(self):
1938
1935
@pytest .mark .parametrize ("bad_val" , ["foo" , 111111111 ])
1939
1936
def test_to_datetime_unit_invalid (self , bad_val ):
1940
1937
if bad_val == "foo" :
1941
- msg = (
1942
- "Unknown datetime string format, unable to parse: "
1943
- f"{ bad_val } , at position 2"
1944
- )
1938
+ msg = "Unknown datetime string format, unable to parse: " f"{ bad_val } "
1945
1939
else :
1946
- msg = "cannot convert input 111111111 with the unit 'D', at position 2 "
1940
+ msg = "cannot convert input 111111111 with the unit 'D'"
1947
1941
with pytest .raises (ValueError , match = msg ):
1948
1942
to_datetime ([1 , 2 , bad_val ], unit = "D" )
1949
1943
@@ -2096,7 +2090,7 @@ def test_dataframe_coerce(self, cache):
2096
2090
2097
2091
msg = (
2098
2092
r'^cannot assemble the datetimes: time data ".+" doesn\'t '
2099
- r'match format "%Y%m%d", at position 1 \.'
2093
+ r'match format "%Y%m%d"\.'
2100
2094
)
2101
2095
with pytest .raises (ValueError , match = msg ):
2102
2096
to_datetime (df2 , cache = cache )
@@ -2174,7 +2168,7 @@ def test_dataframe_float(self, cache):
2174
2168
df = DataFrame ({"year" : [2000 , 2001 ], "month" : [1.5 , 1 ], "day" : [1 , 1 ]})
2175
2169
msg = (
2176
2170
r"^cannot assemble the datetimes: unconverted data remains when parsing "
2177
- r'with format ".*": "1", at position 0 .'
2171
+ r'with format ".*": "1".'
2178
2172
)
2179
2173
with pytest .raises (ValueError , match = msg ):
2180
2174
to_datetime (df , cache = cache )
@@ -2196,7 +2190,7 @@ def test_to_datetime_barely_out_of_bounds(self):
2196
2190
# in an in-bounds datetime
2197
2191
arr = np .array (["2262-04-11 23:47:16.854775808" ], dtype = object )
2198
2192
2199
- msg = "^Out of bounds nanosecond timestamp: .*, at position 0 "
2193
+ msg = "^Out of bounds nanosecond timestamp: .*"
2200
2194
with pytest .raises (OutOfBoundsDatetime , match = msg ):
2201
2195
to_datetime (arr )
2202
2196
@@ -2231,10 +2225,7 @@ def test_to_datetime_iso8601_fails(self, input, format, exact):
2231
2225
# `format` is longer than the string, so this fails regardless of `exact`
2232
2226
with pytest .raises (
2233
2227
ValueError ,
2234
- match = (
2235
- rf"time data \"{ input } \" doesn't match format "
2236
- rf"\" { format } \", at position 0"
2237
- ),
2228
+ match = (rf"time data \"{ input } \" doesn't match format " rf"\" { format } \"" ),
2238
2229
):
2239
2230
to_datetime (input , format = format , exact = exact )
2240
2231
@@ -2253,10 +2244,9 @@ def test_to_datetime_iso8601_exact_fails(self, input, format):
2253
2244
# `format` is shorter than the date string, so only fails with `exact=True`
2254
2245
msg = "|" .join (
2255
2246
[
2256
- '^unconverted data remains when parsing with format ".*": ".*"'
2257
- f", at position 0. { PARSING_ERR_MSG } $" ,
2258
- f'^time data ".*" doesn\' t match format ".*", at position 0. '
2247
+ '^unconverted data remains when parsing with format ".*": ".*". '
2259
2248
f"{ PARSING_ERR_MSG } $" ,
2249
+ f'^time data ".*" doesn\' t match format ".*". ' f"{ PARSING_ERR_MSG } $" ,
2260
2250
]
2261
2251
)
2262
2252
with pytest .raises (
@@ -2297,10 +2287,7 @@ def test_to_datetime_iso8601_separator(self, input, format):
2297
2287
# https://github.com/pandas-dev/pandas/issues/12649
2298
2288
with pytest .raises (
2299
2289
ValueError ,
2300
- match = (
2301
- rf"time data \"{ input } \" doesn\'t match format "
2302
- rf"\" { format } \", at position 0"
2303
- ),
2290
+ match = (rf"time data \"{ input } \" doesn\'t match format " rf"\" { format } \"" ),
2304
2291
):
2305
2292
to_datetime (input , format = format )
2306
2293
@@ -2390,8 +2377,7 @@ def test_to_datetime_with_space_in_series(self, cache):
2390
2377
# GH 6428
2391
2378
ser = Series (["10/18/2006" , "10/18/2008" , " " ])
2392
2379
msg = (
2393
- r'^time data " " doesn\'t match format "%m/%d/%Y", '
2394
- rf"at position 2. { PARSING_ERR_MSG } $"
2380
+ r'^time data " " doesn\'t match format "%m/%d/%Y". ' rf"{ PARSING_ERR_MSG } $"
2395
2381
)
2396
2382
with pytest .raises (ValueError , match = msg ):
2397
2383
to_datetime (ser , errors = "raise" , cache = cache )
@@ -2466,7 +2452,7 @@ def test_to_datetime_strings_vs_constructor(self, result):
2466
2452
def test_to_datetime_unprocessable_input (self , cache ):
2467
2453
# GH 4928
2468
2454
# GH 21864
2469
- msg = '^Given date string "1" not likely a datetime, at position 1 $'
2455
+ msg = '^Given date string "1" not likely a datetime$'
2470
2456
with pytest .raises (ValueError , match = msg ):
2471
2457
to_datetime ([1 , "1" ], errors = "raise" , cache = cache )
2472
2458
@@ -2643,7 +2629,7 @@ def test_dayfirst_warnings_invalid_input(self):
2643
2629
ValueError ,
2644
2630
match = (
2645
2631
r'^time data "03/30/2011" doesn\'t match format '
2646
- rf'"%d/%m/%Y", at position 1 . { PARSING_ERR_MSG } $'
2632
+ rf'"%d/%m/%Y". { PARSING_ERR_MSG } $'
2647
2633
),
2648
2634
):
2649
2635
to_datetime (arr , dayfirst = True )
@@ -2714,7 +2700,7 @@ def test_to_datetime_inconsistent_format(self, cache):
2714
2700
ser = Series (np .array (data ))
2715
2701
msg = (
2716
2702
r'^time data "01-02-2011 00:00:00" doesn\'t match format '
2717
- rf'"%m/%d/%Y %H:%M:%S", at position 1 . { PARSING_ERR_MSG } $'
2703
+ rf'"%m/%d/%Y %H:%M:%S". { PARSING_ERR_MSG } $'
2718
2704
)
2719
2705
with pytest .raises (ValueError , match = msg ):
2720
2706
to_datetime (ser , cache = cache )
@@ -2820,7 +2806,7 @@ def test_day_not_in_month_coerce(self, cache, arg, format):
2820
2806
assert isna (to_datetime (arg , errors = "coerce" , format = format , cache = cache ))
2821
2807
2822
2808
def test_day_not_in_month_raise (self , cache ):
2823
- msg = "day is out of range for month: 2015-02-29, at position 0 "
2809
+ msg = "day is out of range for month: 2015-02-29"
2824
2810
with pytest .raises (ValueError , match = msg ):
2825
2811
to_datetime ("2015-02-29" , errors = "raise" , cache = cache )
2826
2812
@@ -2830,34 +2816,34 @@ def test_day_not_in_month_raise(self, cache):
2830
2816
(
2831
2817
"2015-02-29" ,
2832
2818
"%Y-%m-%d" ,
2833
- f"^day is out of range for month, at position 0 . { PARSING_ERR_MSG } $" ,
2819
+ f"^day is out of range for month. { PARSING_ERR_MSG } $" ,
2834
2820
),
2835
2821
(
2836
2822
"2015-29-02" ,
2837
2823
"%Y-%d-%m" ,
2838
- f"^day is out of range for month, at position 0 . { PARSING_ERR_MSG } $" ,
2824
+ f"^day is out of range for month. { PARSING_ERR_MSG } $" ,
2839
2825
),
2840
2826
(
2841
2827
"2015-02-32" ,
2842
2828
"%Y-%m-%d" ,
2843
- '^unconverted data remains when parsing with format "%Y-%m-%d": "2", '
2844
- f"at position 0. { PARSING_ERR_MSG } $" ,
2829
+ '^unconverted data remains when parsing with format "%Y-%m-%d": "2". '
2830
+ f"{ PARSING_ERR_MSG } $" ,
2845
2831
),
2846
2832
(
2847
2833
"2015-32-02" ,
2848
2834
"%Y-%d-%m" ,
2849
- '^time data "2015-32-02" doesn\' t match format "%Y-%d-%m", '
2850
- f"at position 0. { PARSING_ERR_MSG } $" ,
2835
+ '^time data "2015-32-02" doesn\' t match format "%Y-%d-%m". '
2836
+ f"{ PARSING_ERR_MSG } $" ,
2851
2837
),
2852
2838
(
2853
2839
"2015-04-31" ,
2854
2840
"%Y-%m-%d" ,
2855
- f"^day is out of range for month, at position 0 . { PARSING_ERR_MSG } $" ,
2841
+ f"^day is out of range for month. { PARSING_ERR_MSG } $" ,
2856
2842
),
2857
2843
(
2858
2844
"2015-31-04" ,
2859
2845
"%Y-%d-%m" ,
2860
- f"^day is out of range for month, at position 0 . { PARSING_ERR_MSG } $" ,
2846
+ f"^day is out of range for month. { PARSING_ERR_MSG } $" ,
2861
2847
),
2862
2848
],
2863
2849
)
@@ -3226,9 +3212,7 @@ def test_invalid_origins_tzinfo(self):
3226
3212
3227
3213
def test_incorrect_value_exception (self ):
3228
3214
# GH47495
3229
- msg = (
3230
- "Unknown datetime string format, unable to parse: yesterday, at position 1"
3231
- )
3215
+ msg = "Unknown datetime string format, unable to parse: yesterday"
3232
3216
with pytest .raises (ValueError , match = msg ):
3233
3217
to_datetime (["today" , "yesterday" ])
3234
3218
@@ -3249,7 +3233,7 @@ def test_to_datetime_out_of_bounds_with_format_arg(self, format, warning):
3249
3233
assert res .month == 10
3250
3234
assert res .day == 10
3251
3235
else :
3252
- msg = "unconverted data remains when parsing with format.*, at position 0 "
3236
+ msg = "unconverted data remains when parsing with format.*"
3253
3237
with pytest .raises (ValueError , match = msg ):
3254
3238
to_datetime ("2417-10-10 00:00:00.00" , format = format )
3255
3239
@@ -3473,9 +3457,7 @@ def test_to_datetime_mixed_or_iso_exact(exact, format):
3473
3457
3474
3458
def test_to_datetime_mixed_not_necessarily_iso8601_raise ():
3475
3459
# https://github.com/pandas-dev/pandas/issues/50411
3476
- with pytest .raises (
3477
- ValueError , match = "Time data 01-01-2000 is not ISO8601 format, at position 1"
3478
- ):
3460
+ with pytest .raises (ValueError , match = "Time data 01-01-2000 is not ISO8601 format" ):
3479
3461
to_datetime (["2020-01-01" , "01-01-2000" ], format = "ISO8601" )
3480
3462
3481
3463
@@ -3500,6 +3482,15 @@ def test_unknown_tz_raises():
3500
3482
to_datetime ([dtstr ])
3501
3483
3502
3484
3485
+ def test_unformatted_input_raises ():
3486
+ valid , invalid = "2024-01-01" , "N"
3487
+ ser = Series ([valid ] * start_caching_at + [invalid ])
3488
+ msg = 'time data "N" doesn\' t match format "%Y-%m-%d"'
3489
+
3490
+ with pytest .raises (ValueError , match = msg ):
3491
+ to_datetime (ser , format = "%Y-%m-%d" , exact = True , cache = True )
3492
+
3493
+
3503
3494
def test_from_numeric_arrow_dtype (any_numeric_ea_dtype ):
3504
3495
# GH 52425
3505
3496
pytest .importorskip ("pyarrow" )
0 commit comments