21
21
iNaT ,
22
22
parsing ,
23
23
)
24
- from pandas .compat import WASM
24
+ from pandas .compat import (
25
+ PY314 ,
26
+ WASM ,
27
+ )
25
28
from pandas .errors import (
26
29
OutOfBoundsDatetime ,
27
30
OutOfBoundsTimedelta ,
57
60
r"alongside this."
58
61
)
59
62
63
+ if PY314 :
64
+ NOT_99 = ", not 99"
65
+ DAY_IS_OUT_OF_RANGE = (
66
+ r"day \d{1,2} must be in range 1\.\.\d{1,2} for "
67
+ r"month \d{1,2} in year \d{4}"
68
+ )
69
+ else :
70
+ NOT_99 = ""
71
+ DAY_IS_OUT_OF_RANGE = "day is out of range for month"
72
+
60
73
61
74
class TestTimeConversionFormats :
62
75
def test_to_datetime_readonly (self , writable ):
@@ -1378,7 +1391,7 @@ def test_datetime_invalid_scalar(self, value, format):
1378
1391
r'^Given date string "a" not likely a datetime$' ,
1379
1392
r'^unconverted data remains when parsing with format "%H:%M:%S": "9". '
1380
1393
f"{ PARSING_ERR_MSG } $" ,
1381
- r "^second must be in 0..59: 00:01:99$" ,
1394
+ rf "^second must be in 0..59{ NOT_99 } : 00:01:99$" ,
1382
1395
]
1383
1396
)
1384
1397
with pytest .raises (ValueError , match = msg ):
@@ -1430,7 +1443,7 @@ def test_datetime_invalid_index(self, values, format):
1430
1443
f"{ PARSING_ERR_MSG } $" ,
1431
1444
r'^unconverted data remains when parsing with format "%H:%M:%S": "9". '
1432
1445
f"{ PARSING_ERR_MSG } $" ,
1433
- r "^second must be in 0..59: 00:01:99$" ,
1446
+ rf "^second must be in 0..59{ NOT_99 } : 00:01:99$" ,
1434
1447
]
1435
1448
)
1436
1449
with pytest .raises (ValueError , match = msg ):
@@ -2857,7 +2870,10 @@ def test_day_not_in_month_coerce(self, cache, arg, format):
2857
2870
assert isna (to_datetime (arg , errors = "coerce" , format = format , cache = cache ))
2858
2871
2859
2872
def test_day_not_in_month_raise (self , cache ):
2860
- msg = "day is out of range for month: 2015-02-29"
2873
+ if PY314 :
2874
+ msg = "day 29 must be in range 1..28 for month 2 in year 2015: 2015-02-29"
2875
+ else :
2876
+ msg = "day is out of range for month: 2015-02-29"
2861
2877
with pytest .raises (ValueError , match = msg ):
2862
2878
to_datetime ("2015-02-29" , errors = "raise" , cache = cache )
2863
2879
@@ -2867,12 +2883,12 @@ def test_day_not_in_month_raise(self, cache):
2867
2883
(
2868
2884
"2015-02-29" ,
2869
2885
"%Y-%m-%d" ,
2870
- f"^day is out of range for month . { PARSING_ERR_MSG } $" ,
2886
+ f"^{ DAY_IS_OUT_OF_RANGE } . { PARSING_ERR_MSG } $" ,
2871
2887
),
2872
2888
(
2873
2889
"2015-29-02" ,
2874
2890
"%Y-%d-%m" ,
2875
- f"^day is out of range for month . { PARSING_ERR_MSG } $" ,
2891
+ f"^{ DAY_IS_OUT_OF_RANGE } . { PARSING_ERR_MSG } $" ,
2876
2892
),
2877
2893
(
2878
2894
"2015-02-32" ,
@@ -2889,12 +2905,12 @@ def test_day_not_in_month_raise(self, cache):
2889
2905
(
2890
2906
"2015-04-31" ,
2891
2907
"%Y-%m-%d" ,
2892
- f"^day is out of range for month . { PARSING_ERR_MSG } $" ,
2908
+ f"^{ DAY_IS_OUT_OF_RANGE } . { PARSING_ERR_MSG } $" ,
2893
2909
),
2894
2910
(
2895
2911
"2015-31-04" ,
2896
2912
"%Y-%d-%m" ,
2897
- f"^day is out of range for month . { PARSING_ERR_MSG } $" ,
2913
+ f"^{ DAY_IS_OUT_OF_RANGE } . { PARSING_ERR_MSG } $" ,
2898
2914
),
2899
2915
],
2900
2916
)
0 commit comments