@@ -82,6 +82,11 @@ class DateParseError(ValueError):
82
82
_DEFAULT_DATETIME = datetime(1 , 1 , 1 ).replace(hour = 0 , minute = 0 ,
83
83
second = 0 , microsecond = 0 )
84
84
85
+ PARSING_WARNING_MSG = (
86
+ " Parsing '{date_string}' in {format} format. Provide format "
87
+ " or specify infer_datetime_format=True for consistent parsing."
88
+ )
89
+
85
90
cdef:
86
91
set _not_datelike_strings = {' a' , ' A' , ' m' , ' M' , ' p' , ' P' , ' t' , ' T' }
87
92
@@ -175,38 +180,26 @@ cdef inline object _parse_delimited_date(str date_string, bint dayfirst):
175
180
if (month > MAX_MONTH or (day <= MAX_MONTH and dayfirst)) and can_swap:
176
181
day, month = month, day
177
182
swapped_day_and_month = True
178
- if PY_VERSION_HEX >= 0x03060100 :
179
- # In Python <= 3.6.0 there is no range checking for invalid dates
180
- # in C api, thus we call faster C version for 3.6.1 or newer
181
-
182
- if dayfirst and not swapped_day_and_month:
183
- warnings.warn(
184
- f" Parsing '{date_string}' in MM/DD/YYYY format. Provide format "
185
- " or specify infer_datetime_format=True for consistent parsing." ,
186
- stacklevel = 4 ,
187
- )
188
- elif not dayfirst and swapped_day_and_month:
189
- warnings.warn(
190
- f" Parsing '{date_string}' in DD/MM/YYYY format. Provide format "
191
- " or specify infer_datetime_format=True for consistent parsing." ,
192
- stacklevel = 4 ,
193
- )
194
-
195
- return datetime_new(year, month, day, 0 , 0 , 0 , 0 , None ), reso
196
-
197
183
if dayfirst and not swapped_day_and_month:
198
184
warnings.warn(
199
- f" Parsing '{date_string}' in MM/DD/YYYY format. Provide format or "
200
- " specify infer_datetime_format=True for consistent parsing." ,
185
+ PARSING_WARNING_MSG.format(
186
+ date_string = date_string,
187
+ format = ' MM/DD/YYYY'
188
+ ),
201
189
stacklevel = 4 ,
202
190
)
203
191
elif not dayfirst and swapped_day_and_month:
204
192
warnings.warn(
205
- f" Parsing '{date_string}' in DD/MM/YYYY format. Provide format or "
206
- " specify infer_datetime_format=True for consistent parsing." ,
193
+ PARSING_WARNING_MSG.format(
194
+ date_string = date_string,
195
+ format = ' DD/MM/YYYY'
196
+ ),
207
197
stacklevel = 4 ,
208
198
)
209
-
199
+ if PY_VERSION_HEX >= 0x03060100 :
200
+ # In Python <= 3.6.0 there is no range checking for invalid dates
201
+ # in C api, thus we call faster C version for 3.6.1 or newer
202
+ return datetime_new(year, month, day, 0 , 0 , 0 , 0 , None ), reso
210
203
return datetime(year, month, day, 0 , 0 , 0 , 0 , None ), reso
211
204
212
205
raise DateParseError(f" Invalid date specified ({month}/{day})" )
0 commit comments