You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* 🗑️ deprecate infer_datetime_format, make strict
* 🚨 add warning about dayfirst
* ✅ add/update tests
* 🚨 add warning if format cant be guessed
* 🥅 catch warnings
* 📝 update docs
* 📝 add example of reading csv file with mixed formats
* 🗑️ removed now outdated tests / clean inputs
* 📝 clarify whatsnew and user-guide
* 🎨
* guess %Y-%m format
* Detect format from first non-na, but also exclude now and today
* ✅ fixup tests based on now and today parsing
* fixup after merge
* fixup after merge
* fixup test
* remove outdated doctest
* xfail test based on issue 49767
* wip
* add back examples of formats which can be guessed
* start fixing up
* fixups from reviews
* lint
* put tests back
* shorten diff
* add example of string which cannot be guessed
* add deprecated directive, construct expected explicitly, explicit UserWarning, reword row-wise and column-wise
* remove redundant example
* restore newline
* double backticks around False, explicitly raise UserWarning
* reword warning
* test both dayfirst True and False
* postmerge fixup
* unimportant typo to restart CI
Co-authored-by: MarcoGorelli <>
Copy file name to clipboardExpand all lines: doc/source/whatsnew/v2.0.0.rst
+33-1
Original file line number
Diff line number
Diff line change
@@ -411,6 +411,38 @@ Optional libraries below the lowest tested version may still work, but are not c
411
411
412
412
See :ref:`install.dependencies` and :ref:`install.optional_dependencies` for more.
413
413
414
+
Datetimes are now parsed with a consistent format
415
+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
416
+
417
+
In the past, :func:`to_datetime` guessed the format for each element independently. This was appropriate for some cases where elements had mixed date formats - however, it would regularly cause problems when users expected a consistent format but the function would switch formats between elements. As of version 2.0.0, parsing will use a consistent format, determined by the first non-NA value (unless the user specifies a format, in which case that is used).
418
+
419
+
*Old behavior*:
420
+
421
+
.. code-block:: ipython
422
+
423
+
In [1]: ser = pd.Series(['13-01-2000', '12-01-2000'])
424
+
In [2]: pd.to_datetime(ser)
425
+
Out[2]:
426
+
0 2000-01-13
427
+
1 2000-12-01
428
+
dtype: datetime64[ns]
429
+
430
+
*New behavior*:
431
+
432
+
.. ipython:: python
433
+
:okwarning:
434
+
435
+
ser = pd.Series(['13-01-2000', '12-01-2000'])
436
+
pd.to_datetime(ser)
437
+
438
+
Note that this affects :func:`read_csv` as well.
439
+
440
+
If you still need to parse dates with inconsistent formats, you'll need to apply :func:`to_datetime`
441
+
to each element individually, e.g. ::
442
+
443
+
ser = pd.Series(['13-01-2000', '12 January 2000'])
444
+
ser.apply(pd.to_datetime)
445
+
414
446
.. _whatsnew_200.api_breaking.other:
415
447
416
448
Other API changes
@@ -453,7 +485,7 @@ Other API changes
453
485
454
486
Deprecations
455
487
~~~~~~~~~~~~
456
-
-
488
+
- Deprecated argument ``infer_datetime_format`` in :func:`to_datetime` and :func:`read_csv`, as a strict version of it is now the default (:issue:`48621`)
0 commit comments