DEPR: to_datetime with integer/float values and format argument#65181
Closed
jbrockmendel wants to merge 4 commits intopandas-dev:mainfrom
Closed
DEPR: to_datetime with integer/float values and format argument#65181jbrockmendel wants to merge 4 commits intopandas-dev:mainfrom
jbrockmendel wants to merge 4 commits intopandas-dev:mainfrom
Conversation
Deprecate the implicit str() cast of integer/float values in array_strptime when a format argument is provided. Users should explicitly convert to strings first, e.g. data.astype(str). Also fix internal callers (_assemble_from_unit_mappings and _handle_date_column) to convert numeric data to strings before calling to_datetime with a format, so they don't trigger the deprecation. closes pandas-dev#55663 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Replace object-dtype pre-conversion with warnings.catch_warnings() to suppress the Pandas4Warning. This has zero performance overhead compared to the pre-deprecation code, since the ensure_object conversion was already happening inside _convert_listlike_datetimes. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…path internally Reword the deprecation message in array_strptime to correctly state that integers/floats will be interpreted via the 'unit' keyword in a future version (rather than rejected), and recommend casting to strings explicitly without prescribing .astype(str) (which would mishandle Timestamps in mixed-dtype object arrays). Also replace the warnings.catch_warnings() suppression in the two internal callers (_assemble_from_unit_mappings and _handle_date_column) with explicit string conversion, so they use the future-friendly path directly rather than relying on suppression. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
str()cast of integer/float values inarray_strptimewhen aformatargument is provided toto_datetime. In a future version, passing numeric data withformatwill raise a TypeError._assemble_from_unit_mappingsindatetimes.pyand_handle_date_columninsql.py) to convert numeric data to strings before callingto_datetimewith a format, so they don't trigger the deprecation.pd.to_datetime(data.astype(str), format="%Y%m%d").closes #55663
Test plan
test_to_datetime.pytests pass (including with-W error::Pandas4Warning)test_sql.pytests passtest_stata.py, JSON IO, andDatetimeIndextests unaffected🤖 Generated with Claude Code