Skip to content

Commit 7d06940

Browse files
committed
WARN: clarify warning message from to_datetime when dayfirst cant be respected
1 parent 33c96e2 commit 7d06940

File tree

3 files changed

+5
-6
lines changed

3 files changed

+5
-6
lines changed

doc/source/whatsnew/v1.5.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -727,6 +727,7 @@ Other Deprecations
727727
- Deprecated the ``display.column_space`` global configuration option (:issue:`7576`)
728728
- Deprecated the argument ``na_sentinel`` in :func:`factorize`, :meth:`Index.factorize`, and :meth:`.ExtensionArray.factorize`; pass ``use_na_sentinel=True`` instead to use the sentinel ``-1`` for NaN values and ``use_na_sentinel=False`` instead of ``na_sentinel=None`` to encode NaN values (:issue:`46910`)
729729
- Deprecated :meth:`DataFrameGroupBy.transform` not aligning the result when the UDF returned DataFrame (:issue:`45648`)
730+
- Clarified warning from :meth:`pandas.to_datetime` when delimited dates can't be parsed in accordance to specified ``dayfirst`` argument (:issue:`46210`)
730731

731732

732733
.. ---------------------------------------------------------------------------

pandas/_libs/tslibs/parsing.pyx

+3-3
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ _DEFAULT_DATETIME = datetime(1, 1, 1).replace(hour=0, minute=0,
8787
PARSING_WARNING_MSG = (
8888
"Parsing dates in {format} format when dayfirst={dayfirst} was specified. "
8989
"This may lead to inconsistently-parsed dates! Specify a format "
90-
"for consistent parsing."
90+
"to ensure consistent parsing."
9191
)
9292

9393
cdef:
@@ -196,8 +196,8 @@ cdef inline object _parse_delimited_date(str date_string, bint dayfirst):
196196
warnings.warn(
197197
PARSING_WARNING_MSG.format(
198198
date_string=date_string,
199-
format='DD/MM/YYYY'
200-
dayfirst='False',
199+
format='DD/MM/YYYY',
200+
dayfirst='False (the default)',
201201
),
202202
stacklevel=4,
203203
)

pandas/tests/io/parser/test_parse_dates.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -1677,9 +1677,7 @@ def test_parse_delimited_date_swap_with_warning(
16771677
):
16781678
parser = all_parsers
16791679
expected = DataFrame({0: [expected]}, dtype="datetime64[ns]")
1680-
warning_msg = (
1681-
"Provide format or specify infer_datetime_format=True for consistent parsing"
1682-
)
1680+
warning_msg = "Specify a format to ensure consistent parsing"
16831681
with tm.assert_produces_warning(UserWarning, match=warning_msg):
16841682
result = parser.read_csv(
16851683
StringIO(date_string), header=None, dayfirst=dayfirst, parse_dates=[0]

0 commit comments

Comments
 (0)