pandas 2.0.0, released on April 3, 2023, changes how the Python data-analysis library interprets date strings. Instead of guessing each value’s format separately, to_datetime() uses the first non-missing value to infer a common format when it can. The release notes say read_csv() is affected too. For teams importing business records, a migration check needs to establish whether the dates still mean the same thing, not only whether the job finishes. [S1][S2]
The release notes illustrate the problem with two strings: '13-01-2000' and '12-01-2000'. Under the old behavior, the first became January 13, 2000, while the second became December 1, 2000. Applying the day-month-year format established by the first value instead makes the second January 12. Both interpretations produce valid dates. An error count alone therefore cannot identify that change in meaning. [S1]
For a feed with a known date format, supply that pattern through format rather than leaving it to inference. The API documentation gives '%d/%m/%Y' as an example; matching is exact by default. dayfirst=True is a different control: it prefers day-first parsing but does not strictly require it. It does not validate that every record follows a day-first convention. [S2]
For genuinely mixed-format inputs, format='mixed' infers a format for each element. The documentation calls that option risky and suggests considering dayfirst alongside it. That returns a decision to each value rather than establishing one format for the feed. For strings that are all ISO 8601 dates or times but differ in formatting, format='ISO8601' offers a narrower choice. The release notes show a date-only string alongside one that includes a time. [S1][S2]
Invalid-value handling is a separate decision. to_datetime() raises an exception on invalid parsing by default. With errors='coerce', it substitutes NaT, pandas’ missing date/time value; the documentation says this also applies to dates outside the supported range. errors='ignore' returns the input on invalid parsing. If a job uses coercion to keep running, compare its missing-date count as well as its interpreted dates: successful completion can conceal values that were not converted. [S2]
The new inference is not an unconditional guarantee of consistency. In the 2.0.0 implementation, if pandas cannot infer a format and there is another non-null element, it warns that it will parse individually using dateutil and recommends specifying a format. Setting infer_datetime_format=False is not a switch back to the old behavior: the argument is deprecated in 2.0.0, and the documentation says passing it has no effect. [S2]
Source documents
- pandas 2.0.0 release notes — pinned release sourcehttps://raw.githubusercontent.com/pandas-dev/pandas/478d340667831908b5b4bf09a2787a11a14560c9/doc/source/whatsnew/v2.0.0.rst
- pandas 2.0.0 to_datetime API documentation and implementationhttps://raw.githubusercontent.com/pandas-dev/pandas/478d340667831908b5b4bf09a2787a11a14560c9/pandas/core/tools/datetimes.py
