Skip to content

Commit 07834ed

Browse files
committed
add to to_datetime docstring, add whatsnew note
1 parent 15797a8 commit 07834ed

File tree

2 files changed

+27
-7
lines changed

2 files changed

+27
-7
lines changed

doc/source/whatsnew/v1.4.0.rst

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,19 @@ Notable bug fixes
5050

5151
These are bug fixes that might have notable behavior changes.
5252

53-
.. _whatsnew_140.notable_bug_fixes.notable_bug_fix1:
53+
.. _whatsnew_140.notable_bug_fixes.inconsistent_date_string_parsing:
5454

55-
notable_bug_fix1
56-
^^^^^^^^^^^^^^^^
55+
Inconsistent date string parsing
56+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
57+
58+
The ``dayfirst`` option of :func:`to_datetime` isn't strict, and this can lead to surprising behaviour:
59+
60+
.. ipython:: python
61+
:okwarning:
62+
63+
pd.to_datetime(["31-12-2021"], dayfirst=False)
64+
65+
Now, a warning will be raised if a date string cannot be parsed accordance to the given ``dayfirst`` value.
5766

5867
.. _whatsnew_140.notable_bug_fixes.notable_bug_fix2:
5968

@@ -196,6 +205,7 @@ Categorical
196205
Datetimelike
197206
^^^^^^^^^^^^
198207
- Bug in :class:`DataFrame` constructor unnecessarily copying non-datetimelike 2D object arrays (:issue:`39272`)
208+
- :func:`to_datetime` would silently swap ``MM/DD/YYYY`` and ``DD/MM/YYYY`` formats if the given ``dayfirst`` option could not be respected - now, a warning is raised (:issue:`12585`)
199209
-
200210

201211
Timedelta

pandas/core/tools/datetimes.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -701,8 +701,15 @@ def to_datetime(
701701
Specify a date parse order if `arg` is str or its list-likes.
702702
If True, parses dates with the day first, eg 10/11/12 is parsed as
703703
2012-11-10.
704-
Warning: dayfirst=True is not strict, but will prefer to parse
705-
with day first (this is a known bug, based on dateutil behavior).
704+
705+
.. warning::
706+
707+
dayfirst=True is not strict, but will prefer to parse
708+
with day first (this is a known bug, based on dateutil behavior).
709+
If a date string cannot be parsed in accordance with the given
710+
`dayfirst` option (e.g. ``to_datetime(['31-12-2021'], dayfirst=False)``)
711+
then a warning will be shown.
712+
706713
yearfirst : bool, default False
707714
Specify a date parse order if `arg` is str or its list-likes.
708715
@@ -711,8 +718,11 @@ def to_datetime(
711718
- If both dayfirst and yearfirst are True, yearfirst is preceded (same
712719
as dateutil).
713720
714-
Warning: yearfirst=True is not strict, but will prefer to parse
715-
with year first (this is a known bug, based on dateutil behavior).
721+
.. warning::
722+
723+
yearfirst=True is not strict, but will prefer to parse
724+
with year first (this is a known bug, based on dateutil behavior).
725+
716726
utc : bool, default None
717727
Return UTC DatetimeIndex if True (converting any tz-aware
718728
datetime.datetime objects as well).

0 commit comments

Comments
 (0)