22
22
iNaT ,
23
23
parsing ,
24
24
)
25
+ from pandas .compat import PY314
25
26
from pandas .errors import (
26
27
OutOfBoundsDatetime ,
27
28
OutOfBoundsTimedelta ,
57
58
r"alongside this."
58
59
)
59
60
61
+ if PY314 :
62
+ NOT_99 = ", not 99"
63
+ DAY_IS_OUT_OF_RANGE = (
64
+ r"day \d{1,2} must be in range 1\.\.\d{1,2} for month \d{1,2} in year \d{4}"
65
+ ", at position 0"
66
+ )
67
+ else :
68
+ NOT_99 = ""
69
+ DAY_IS_OUT_OF_RANGE = "day is out of range for month, at position 0"
70
+
71
+
60
72
pytestmark = pytest .mark .filterwarnings (
61
73
"ignore:errors='ignore' is deprecated:FutureWarning"
62
74
)
@@ -1451,7 +1463,7 @@ def test_datetime_invalid_scalar(self, value, format):
1451
1463
r'^Given date string "a" not likely a datetime, at position 0$' ,
1452
1464
r'^unconverted data remains when parsing with format "%H:%M:%S": "9", '
1453
1465
f"at position 0. { PARSING_ERR_MSG } $" ,
1454
- r "^second must be in 0..59: 00:01:99, at position 0$" ,
1466
+ rf "^second must be in 0..59{ NOT_99 } : 00:01:99, at position 0$" ,
1455
1467
]
1456
1468
)
1457
1469
with pytest .raises (ValueError , match = msg ):
@@ -1509,7 +1521,7 @@ def test_datetime_invalid_index(self, values, format):
1509
1521
f"{ PARSING_ERR_MSG } $" ,
1510
1522
r'^unconverted data remains when parsing with format "%H:%M:%S": "9", '
1511
1523
f"at position 0. { PARSING_ERR_MSG } $" ,
1512
- r "^second must be in 0..59: 00:01:99, at position 0$" ,
1524
+ rf "^second must be in 0..59{ NOT_99 } : 00:01:99, at position 0$" ,
1513
1525
]
1514
1526
)
1515
1527
with pytest .raises (ValueError , match = msg ):
@@ -3012,7 +3024,10 @@ def test_day_not_in_month_coerce(self, cache, arg, format):
3012
3024
assert isna (to_datetime (arg , errors = "coerce" , format = format , cache = cache ))
3013
3025
3014
3026
def test_day_not_in_month_raise (self , cache ):
3015
- msg = "day is out of range for month: 2015-02-29, at position 0"
3027
+ if PY314 :
3028
+ msg = "day 29 must be in range 1..28 for month 2 in year 2015: 2015-02-29"
3029
+ else :
3030
+ msg = "day is out of range for month: 2015-02-29"
3016
3031
with pytest .raises (ValueError , match = msg ):
3017
3032
to_datetime ("2015-02-29" , errors = "raise" , cache = cache )
3018
3033
@@ -3022,12 +3037,12 @@ def test_day_not_in_month_raise(self, cache):
3022
3037
(
3023
3038
"2015-02-29" ,
3024
3039
"%Y-%m-%d" ,
3025
- f"^day is out of range for month, at position 0 . { PARSING_ERR_MSG } $" ,
3040
+ f"^{ DAY_IS_OUT_OF_RANGE } . { PARSING_ERR_MSG } $" ,
3026
3041
),
3027
3042
(
3028
3043
"2015-29-02" ,
3029
3044
"%Y-%d-%m" ,
3030
- f"^day is out of range for month, at position 0 . { PARSING_ERR_MSG } $" ,
3045
+ f"^{ DAY_IS_OUT_OF_RANGE } . { PARSING_ERR_MSG } $" ,
3031
3046
),
3032
3047
(
3033
3048
"2015-02-32" ,
@@ -3044,12 +3059,12 @@ def test_day_not_in_month_raise(self, cache):
3044
3059
(
3045
3060
"2015-04-31" ,
3046
3061
"%Y-%m-%d" ,
3047
- f"^day is out of range for month, at position 0 . { PARSING_ERR_MSG } $" ,
3062
+ f"^{ DAY_IS_OUT_OF_RANGE } . { PARSING_ERR_MSG } $" ,
3048
3063
),
3049
3064
(
3050
3065
"2015-31-04" ,
3051
3066
"%Y-%d-%m" ,
3052
- f"^day is out of range for month, at position 0 . { PARSING_ERR_MSG } $" ,
3067
+ f"^{ DAY_IS_OUT_OF_RANGE } . { PARSING_ERR_MSG } $" ,
3053
3068
),
3054
3069
],
3055
3070
)
0 commit comments