2222 iNaT ,
2323 parsing ,
2424)
25+ from pandas .compat import PY314
2526from pandas .errors import (
2627 OutOfBoundsDatetime ,
2728 OutOfBoundsTimedelta ,
5758 r"alongside this."
5859)
5960
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+ )
66+ else :
67+ NOT_99 = ""
68+ DAY_IS_OUT_OF_RANGE = "day is out of range for month"
69+
70+
6071pytestmark = pytest .mark .filterwarnings (
6172 "ignore:errors='ignore' is deprecated:FutureWarning"
6273)
@@ -1448,10 +1459,10 @@ def test_datetime_invalid_scalar(self, value, format):
14481459 [
14491460 r'^time data "a" doesn\'t match format "%H:%M:%S", at position 0. '
14501461 f"{ PARSING_ERR_MSG } $" ,
1451- r'^Given date string "a" not likely a datetime, at position 0 $' ,
1452- r'^unconverted data remains when parsing with format "%H:%M:%S": "9", '
1453- f"at position 0. { PARSING_ERR_MSG } $" ,
1454- r "^second must be in 0..59: 00:01:99, at position 0 $" ,
1462+ r'^Given date string "a" not likely a datetime$' ,
1463+ r'^unconverted data remains when parsing with format "%H:%M:%S": "9". '
1464+ f"{ PARSING_ERR_MSG } $" ,
1465+ rf "^second must be in 0..59{ NOT_99 } : 00:01:99$" ,
14551466 ]
14561467 )
14571468 with pytest .raises (ValueError , match = msg ):
@@ -1507,9 +1518,9 @@ def test_datetime_invalid_index(self, values, format):
15071518 r'^Given date string "a" not likely a datetime, at position 0$' ,
15081519 r'^time data "a" doesn\'t match format "%H:%M:%S", at position 0. '
15091520 f"{ PARSING_ERR_MSG } $" ,
1510- r'^unconverted data remains when parsing with format "%H:%M:%S": "9", '
1511- f"at position 0. { PARSING_ERR_MSG } $" ,
1512- r "^second must be in 0..59: 00:01:99, at position 0 $" ,
1521+ r'^unconverted data remains when parsing with format "%H:%M:%S": "9". '
1522+ f"{ PARSING_ERR_MSG } $" ,
1523+ rf "^second must be in 0..59{ NOT_99 } : 00:01:99$" ,
15131524 ]
15141525 )
15151526 with pytest .raises (ValueError , match = msg ):
@@ -3012,7 +3023,10 @@ def test_day_not_in_month_coerce(self, cache, arg, format):
30123023 assert isna (to_datetime (arg , errors = "coerce" , format = format , cache = cache ))
30133024
30143025 def test_day_not_in_month_raise (self , cache ):
3015- msg = "day is out of range for month: 2015-02-29, at position 0"
3026+ if PY314 :
3027+ msg = "day 29 must be in range 1..28 for month 2 in year 2015: 2015-02-29"
3028+ else :
3029+ msg = "day is out of range for month: 2015-02-29"
30163030 with pytest .raises (ValueError , match = msg ):
30173031 to_datetime ("2015-02-29" , errors = "raise" , cache = cache )
30183032
@@ -3022,12 +3036,12 @@ def test_day_not_in_month_raise(self, cache):
30223036 (
30233037 "2015-02-29" ,
30243038 "%Y-%m-%d" ,
3025- f"^day is out of range for month, at position 0 . { PARSING_ERR_MSG } $" ,
3039+ f"^{ DAY_IS_OUT_OF_RANGE } . { PARSING_ERR_MSG } $" ,
30263040 ),
30273041 (
30283042 "2015-29-02" ,
30293043 "%Y-%d-%m" ,
3030- f"^day is out of range for month, at position 0 . { PARSING_ERR_MSG } $" ,
3044+ f"^{ DAY_IS_OUT_OF_RANGE } . { PARSING_ERR_MSG } $" ,
30313045 ),
30323046 (
30333047 "2015-02-32" ,
@@ -3044,12 +3058,12 @@ def test_day_not_in_month_raise(self, cache):
30443058 (
30453059 "2015-04-31" ,
30463060 "%Y-%m-%d" ,
3047- f"^day is out of range for month, at position 0 . { PARSING_ERR_MSG } $" ,
3061+ f"^{ DAY_IS_OUT_OF_RANGE } . { PARSING_ERR_MSG } $" ,
30483062 ),
30493063 (
30503064 "2015-31-04" ,
30513065 "%Y-%d-%m" ,
3052- f"^day is out of range for month, at position 0 . { PARSING_ERR_MSG } $" ,
3066+ f"^{ DAY_IS_OUT_OF_RANGE } . { PARSING_ERR_MSG } $" ,
30533067 ),
30543068 ],
30553069 )
0 commit comments