21
21
iNaT ,
22
22
parsing ,
23
23
)
24
- from pandas .compat import WASM
24
+ from pandas .compat import WASM , PY314
25
25
from pandas .errors import (
26
26
OutOfBoundsDatetime ,
27
27
OutOfBoundsTimedelta ,
57
57
r"alongside this."
58
58
)
59
59
60
+ if PY314 :
61
+ NOT_99 = ", not 99"
62
+ DAY_IS_OUT_OF_RANGE = "day \d{1,2} must be in range 1\.\.\d{1,2} for month \d{1,2} in year \d{4}"
63
+ else :
64
+ NOT_99 = ""
65
+ DAY_IS_OUT_OF_RANGE = "day is out of range for month"
66
+
60
67
61
68
class TestTimeConversionFormats :
62
69
def test_to_datetime_readonly (self , writable ):
@@ -1372,7 +1379,7 @@ def test_datetime_invalid_scalar(self, value, format):
1372
1379
r'^Given date string "a" not likely a datetime$' ,
1373
1380
r'^unconverted data remains when parsing with format "%H:%M:%S": "9". '
1374
1381
f"{ PARSING_ERR_MSG } $" ,
1375
- r "^second must be in 0..59: 00:01:99$" ,
1382
+ fr "^second must be in 0..59{ NOT_99 } : 00:01:99$" ,
1376
1383
]
1377
1384
)
1378
1385
with pytest .raises (ValueError , match = msg ):
@@ -1424,7 +1431,7 @@ def test_datetime_invalid_index(self, values, format):
1424
1431
f"{ PARSING_ERR_MSG } $" ,
1425
1432
r'^unconverted data remains when parsing with format "%H:%M:%S": "9". '
1426
1433
f"{ PARSING_ERR_MSG } $" ,
1427
- r "^second must be in 0..59: 00:01:99$" ,
1434
+ fr "^second must be in 0..59{ NOT_99 } : 00:01:99$" ,
1428
1435
]
1429
1436
)
1430
1437
with pytest .raises (ValueError , match = msg ):
@@ -2851,7 +2858,10 @@ def test_day_not_in_month_coerce(self, cache, arg, format):
2851
2858
assert isna (to_datetime (arg , errors = "coerce" , format = format , cache = cache ))
2852
2859
2853
2860
def test_day_not_in_month_raise (self , cache ):
2854
- msg = "day is out of range for month: 2015-02-29"
2861
+ if PY314 :
2862
+ msg = "day 29 must be in range 1..28 for month 2 in year 2015: 2015-02-29"
2863
+ else :
2864
+ msg = "day is out of range for month: 2015-02-29"
2855
2865
with pytest .raises (ValueError , match = msg ):
2856
2866
to_datetime ("2015-02-29" , errors = "raise" , cache = cache )
2857
2867
@@ -2861,12 +2871,12 @@ def test_day_not_in_month_raise(self, cache):
2861
2871
(
2862
2872
"2015-02-29" ,
2863
2873
"%Y-%m-%d" ,
2864
- f"^day is out of range for month . { PARSING_ERR_MSG } $" ,
2874
+ f"^{ DAY_IS_OUT_OF_RANGE } . { PARSING_ERR_MSG } $" ,
2865
2875
),
2866
2876
(
2867
2877
"2015-29-02" ,
2868
2878
"%Y-%d-%m" ,
2869
- f"^day is out of range for month . { PARSING_ERR_MSG } $" ,
2879
+ f"^{ DAY_IS_OUT_OF_RANGE } . { PARSING_ERR_MSG } $" ,
2870
2880
),
2871
2881
(
2872
2882
"2015-02-32" ,
@@ -2883,12 +2893,12 @@ def test_day_not_in_month_raise(self, cache):
2883
2893
(
2884
2894
"2015-04-31" ,
2885
2895
"%Y-%m-%d" ,
2886
- f"^day is out of range for month . { PARSING_ERR_MSG } $" ,
2896
+ f"^{ DAY_IS_OUT_OF_RANGE } . { PARSING_ERR_MSG } $" ,
2887
2897
),
2888
2898
(
2889
2899
"2015-31-04" ,
2890
2900
"%Y-%d-%m" ,
2891
- f"^day is out of range for month . { PARSING_ERR_MSG } $" ,
2901
+ f"^{ DAY_IS_OUT_OF_RANGE } . { PARSING_ERR_MSG } $" ,
2892
2902
),
2893
2903
],
2894
2904
)
0 commit comments