Skip to content

BUG: fix to_timedelta ignoring unit for mixed round/non-round floats#65170

Open
jbrockmendel wants to merge 1 commit intopandas-dev:mainfrom
jbrockmendel:bug-65150
Open

BUG: fix to_timedelta ignoring unit for mixed round/non-round floats#65170
jbrockmendel wants to merge 1 commit intopandas-dev:mainfrom
jbrockmendel:bug-65150

Conversation

@jbrockmendel
Copy link
Copy Markdown
Member

closes #65150

Summary

  • pd.to_timedelta([1.0, 1.01], unit="s") was treating 1.0 as 1 nanosecond instead of 1 second
  • Root cause: in array_to_timedelta64, when a mix of round and non-round floats triggers a resolution-mismatch second pass, integers and round floats were converted using int_reso (the unit's resolution) instead of creso (the target resolution), so their values were stored in the wrong units
  • Fix mirrors the pattern already used in tslib.pyx for datetime conversions: update creso first, then convert using creso as the output resolution

Test plan

  • Added regression test for mixed round/non-round float lists
  • All existing timedelta tests pass (912 passed)
  • Pre-commit hooks pass

🤖 Generated with Claude Code

…andas-dev#65150)

Match the pattern used in tslib.pyx for numeric conversions: update
creso first, then convert using creso as the output resolution. This
ensures that when a resolution mismatch triggers a second pass, all
numeric values (integers, round floats, non-round floats) are converted
to the unified target resolution.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BUG: pd.to_timedelta ignores unit value for certain float values

1 participant