Skip to content

DEPR: to_datetime with integer/float values and format argument#65181

Closed
jbrockmendel wants to merge 4 commits intopandas-dev:mainfrom
jbrockmendel:depr-55663
Closed

DEPR: to_datetime with integer/float values and format argument#65181
jbrockmendel wants to merge 4 commits intopandas-dev:mainfrom
jbrockmendel:depr-55663

Conversation

@jbrockmendel
Copy link
Copy Markdown
Member

Summary

  • Deprecate the implicit str() cast of integer/float values in array_strptime when a format argument is provided to to_datetime. In a future version, passing numeric data with format will raise a TypeError.
  • Fix internal callers (_assemble_from_unit_mappings in datetimes.py and _handle_date_column in sql.py) to convert numeric data to strings before calling to_datetime with a format, so they don't trigger the deprecation.
  • Users should convert to strings first, e.g. pd.to_datetime(data.astype(str), format="%Y%m%d").

closes #55663

Test plan

  • All 939 test_to_datetime.py tests pass (including with -W error::Pandas4Warning)
  • All sqlite test_sql.py tests pass
  • test_stata.py, JSON IO, and DatetimeIndex tests unaffected
  • mypy clean on changed files
  • pre-commit hooks pass

🤖 Generated with Claude Code

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>
@jbrockmendel jbrockmendel added the Deprecate Functionality to remove in pandas label Apr 11, 2026
jbrockmendel and others added 3 commits April 11, 2026 16:01
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>
@jbrockmendel jbrockmendel marked this pull request as ready for review April 17, 2026 00:51
@jbrockmendel jbrockmendel added Mothballed Temporarily-closed PR the author plans to return to and removed Mothballed Temporarily-closed PR the author plans to return to labels Apr 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Deprecate Functionality to remove in pandas Mothballed Temporarily-closed PR the author plans to return to

Projects

None yet

Development

Successfully merging this pull request may close these issues.

API: to_datetime with integers/floats and format desired behavior?

1 participant