Skip to content

Commit e6557c7

Browse files
committed
🎨
1 parent 56867d4 commit e6557c7

File tree

1 file changed

+17
-24
lines changed

1 file changed

+17
-24
lines changed

pandas/_libs/tslibs/parsing.pyx

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,11 @@ class DateParseError(ValueError):
8282
_DEFAULT_DATETIME = datetime(1, 1, 1).replace(hour=0, minute=0,
8383
second=0, microsecond=0)
8484

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+
8590
cdef:
8691
set _not_datelike_strings = {'a', 'A', 'm', 'M', 'p', 'P', 't', 'T'}
8792

@@ -175,38 +180,26 @@ cdef inline object _parse_delimited_date(str date_string, bint dayfirst):
175180
if (month > MAX_MONTH or (day <= MAX_MONTH and dayfirst)) and can_swap:
176181
day, month = month, day
177182
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-
197183
if dayfirst and not swapped_day_and_month:
198184
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+
),
201189
stacklevel=4,
202190
)
203191
elif not dayfirst and swapped_day_and_month:
204192
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+
),
207197
stacklevel=4,
208198
)
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
210203
return datetime(year, month, day, 0, 0, 0, 0, None), reso
211204

212205
raise DateParseError(f"Invalid date specified ({month}/{day})")

0 commit comments

Comments
 (0)