BUG: Timedelta kwargs fall back to coarser resolution on overflow#65168
Open
jbrockmendel wants to merge 2 commits intopandas-dev:mainfrom
Open
BUG: Timedelta kwargs fall back to coarser resolution on overflow#65168jbrockmendel wants to merge 2 commits intopandas-dev:mainfrom
jbrockmendel wants to merge 2 commits intopandas-dev:mainfrom
Conversation
mroeschke
reviewed
Apr 13, 2026
pandas/_libs/tslibs/timedeltas.pyx
Outdated
Comment on lines
+2205
to
+2208
| int(ns) | ||
| + int(us * 1_000) | ||
| + int(ms * 1_000_000) | ||
| + seconds |
Member
There was a problem hiding this comment.
nit: Could we pull this and the one in the try block as a total_ns variable before the try?
mroeschke
reviewed
Apr 13, 2026
Comment on lines
+2210
to
+2211
| if total_ns % 1_000 != 0: | ||
| reso_value, reso_abbrev = total_ns, "ns" |
Member
There was a problem hiding this comment.
This if is equivalent to what happens in the try block above correct? We could just replace the above try with this if/else first right?
Member
Author
There was a problem hiding this comment.
i think they're different in the non-overflow case. e.g. Timedelta(days=1) would give unit="s" if we always use this cascade, whereas we want to default to unit="us".
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (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
pd.Timedelta(days=365_000)and similar kwargs that overflow nanosecond int64 bounds now fall back to coarser resolutions (us, ms, s) instead of raisingOutOfBoundsTimedeltaOverflowErrorcloses #46587
Test plan
days=10**15) still raiseTimedelta(nanoseconds=1000).unit == "ns"(GH#63216), small-value kwargs still get us resolution🤖 Generated with Claude Code