Skip to content

Commit 113bdb3

Browse files
authored
BUG: warning shown when parsing delimited date string even if users can't do anything about it (#50232)
* Revert "Inconsistent date parsing of to_datetime (#42908)" This reverts commit 36e4165. * post-merge fixup * add test * whatsnew Co-authored-by: MarcoGorelli <>
1 parent 0189674 commit 113bdb3

File tree

3 files changed

+9
-24
lines changed

3 files changed

+9
-24
lines changed

doc/source/whatsnew/v2.0.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -775,6 +775,7 @@ Datetimelike
775775
- Bug in ``pandas.tseries.holiday.Holiday`` where a half-open date interval causes inconsistent return types from :meth:`USFederalHolidayCalendar.holidays` (:issue:`49075`)
776776
- Bug in rendering :class:`DatetimeIndex` and :class:`Series` and :class:`DataFrame` with timezone-aware dtypes with ``dateutil`` or ``zoneinfo`` timezones near daylight-savings transitions (:issue:`49684`)
777777
- Bug in :func:`to_datetime` was raising ``ValueError`` when parsing :class:`Timestamp`, ``datetime.datetime``, ``datetime.date``, or ``np.datetime64`` objects when non-ISO8601 ``format`` was passed (:issue:`49298`, :issue:`50036`)
778+
- Bug in :class:`Timestamp` was showing ``UserWarning`` which was not actionable by users (:issue:`50232`)
778779
-
779780

780781
Timedelta

pandas/_libs/tslibs/parsing.pyx

-24
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,6 @@ class DateParseError(ValueError):
8585
_DEFAULT_DATETIME = datetime(1, 1, 1).replace(hour=0, minute=0,
8686
second=0, microsecond=0)
8787

88-
PARSING_WARNING_MSG = (
89-
"Parsing dates in {format} format when dayfirst={dayfirst} was specified. "
90-
"This may lead to inconsistently parsed dates! Specify a format "
91-
"to ensure consistent parsing."
92-
)
93-
9488
cdef:
9589
set _not_datelike_strings = {"a", "A", "m", "M", "p", "P", "t", "T"}
9690

@@ -203,28 +197,10 @@ cdef object _parse_delimited_date(str date_string, bint dayfirst):
203197
# date_string can't be converted to date, above format
204198
return None, None
205199

206-
swapped_day_and_month = False
207200
if 1 <= month <= MAX_DAYS_IN_MONTH and 1 <= day <= MAX_DAYS_IN_MONTH \
208201
and (month <= MAX_MONTH or day <= MAX_MONTH):
209202
if (month > MAX_MONTH or (day <= MAX_MONTH and dayfirst)) and can_swap:
210203
day, month = month, day
211-
swapped_day_and_month = True
212-
if dayfirst and not swapped_day_and_month:
213-
warnings.warn(
214-
PARSING_WARNING_MSG.format(
215-
format="MM/DD/YYYY",
216-
dayfirst="True",
217-
),
218-
stacklevel=find_stack_level(),
219-
)
220-
elif not dayfirst and swapped_day_and_month:
221-
warnings.warn(
222-
PARSING_WARNING_MSG.format(
223-
format="DD/MM/YYYY",
224-
dayfirst="False (the default)",
225-
),
226-
stacklevel=find_stack_level(),
227-
)
228204
# In Python <= 3.6.0 there is no range checking for invalid dates
229205
# in C api, thus we call faster C version for 3.6.1 or newer
230206
return datetime_new(year, month, day, 0, 0, 0, 0, None), reso

pandas/tests/scalar/timestamp/test_timestamp.py

+8
Original file line numberDiff line numberDiff line change
@@ -1082,3 +1082,11 @@ def test_as_unit_non_nano(self):
10821082
== res.nanosecond
10831083
== 0
10841084
)
1085+
1086+
1087+
def test_delimited_date():
1088+
# https://github.com/pandas-dev/pandas/issues/50231
1089+
with tm.assert_produces_warning(None):
1090+
result = Timestamp("13-01-2000")
1091+
expected = Timestamp(2000, 1, 13)
1092+
assert result == expected

0 commit comments

Comments
 (0)