2121 iNaT ,
2222 parsing ,
2323)
24- from pandas .compat import WASM
24+ from pandas .compat import WASM , PY314
2525from pandas .errors import (
2626 OutOfBoundsDatetime ,
2727 OutOfBoundsTimedelta ,
5757 r"alongside this."
5858)
5959
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+
6067
6168class TestTimeConversionFormats :
6269 def test_to_datetime_readonly (self , writable ):
@@ -1372,7 +1379,7 @@ def test_datetime_invalid_scalar(self, value, format):
13721379 r'^Given date string "a" not likely a datetime$' ,
13731380 r'^unconverted data remains when parsing with format "%H:%M:%S": "9". '
13741381 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$" ,
13761383 ]
13771384 )
13781385 with pytest .raises (ValueError , match = msg ):
@@ -1424,7 +1431,7 @@ def test_datetime_invalid_index(self, values, format):
14241431 f"{ PARSING_ERR_MSG } $" ,
14251432 r'^unconverted data remains when parsing with format "%H:%M:%S": "9". '
14261433 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$" ,
14281435 ]
14291436 )
14301437 with pytest .raises (ValueError , match = msg ):
@@ -2851,7 +2858,10 @@ def test_day_not_in_month_coerce(self, cache, arg, format):
28512858 assert isna (to_datetime (arg , errors = "coerce" , format = format , cache = cache ))
28522859
28532860 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"
28552865 with pytest .raises (ValueError , match = msg ):
28562866 to_datetime ("2015-02-29" , errors = "raise" , cache = cache )
28572867
@@ -2861,12 +2871,12 @@ def test_day_not_in_month_raise(self, cache):
28612871 (
28622872 "2015-02-29" ,
28632873 "%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 } $" ,
28652875 ),
28662876 (
28672877 "2015-29-02" ,
28682878 "%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 } $" ,
28702880 ),
28712881 (
28722882 "2015-02-32" ,
@@ -2883,12 +2893,12 @@ def test_day_not_in_month_raise(self, cache):
28832893 (
28842894 "2015-04-31" ,
28852895 "%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 } $" ,
28872897 ),
28882898 (
28892899 "2015-31-04" ,
28902900 "%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 } $" ,
28922902 ),
28932903 ],
28942904 )
0 commit comments