Skip to content

BUG: Series.sum on overflowing timedelta64 raises OutOfBoundsTimedelta (GH-43178)#65926

Merged
jbrockmendel merged 2 commits into
pandas-dev:mainfrom
jbrockmendel:bug-td64-overflow
Jun 23, 2026
Merged

BUG: Series.sum on overflowing timedelta64 raises OutOfBoundsTimedelta (GH-43178)#65926
jbrockmendel merged 2 commits into
pandas-dev:mainfrom
jbrockmendel:bug-td64-overflow

Conversation

@jbrockmendel

Copy link
Copy Markdown
Member

Reference GH-43178.

Split out of GH-65515. This is the standalone, pure-Python half of that PR; GH-65515 retains the closes #43178 line since it also fixes the multiplication overflow.

Summary

Series.sum on a timedelta64 reduction that overflows int64 raised a plain ValueError. It now raises :class:OutOfBoundsTimedelta (a ValueError subclass), matching the rest of pandas' overflow-on-timedelta behavior. Because the new exception is a ValueError subclass, existing code that caught ValueError is unaffected.

>>> td = pd.Timedelta(100000, "D").as_unit("ns")
>>> x = pd.Series([td, td])
>>> (x - x.min()).sum()   # before: ValueError; after: OutOfBoundsTimedelta

Test plan

  • Updated test_td64_summation_overflow to expect OutOfBoundsTimedelta
  • pandas/tests/series/test_reductions.py, pandas/tests/test_nanops.py, pandas/tests/reductions/ pass locally

🤖 Generated with Claude Code

pandas-devGH-43178)

Series.sum on a timedelta64 reduction that overflowed int64 raised a
plain ValueError. Raise OutOfBoundsTimedelta (a ValueError subclass)
instead, matching the rest of pandas' overflow-on-timedelta behavior.

Split out of pandas-devGH-65515, which also tightens timedelta64 multiplication
overflow handling.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@jbrockmendel jbrockmendel added Bug Timedelta Timedelta data type Reduction Operations sum, mean, min, max, etc. labels Jun 21, 2026
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@jbrockmendel jbrockmendel merged commit 1806898 into pandas-dev:main Jun 23, 2026
46 checks passed
@jbrockmendel jbrockmendel deleted the bug-td64-overflow branch June 23, 2026 18:25
Sharl0tteIsTaken added a commit to Sharl0tteIsTaken/pandas that referenced this pull request Jun 25, 2026
…-comparison

* upstream/main: (101 commits)
  TST: add regression test for non-nano datetime to_json with epoch date format (pandas-dev#65960)
  TST: equivalent plot frequencies render identical tick labels (GH#57587) (pandas-dev#65961)
  TST: x-axis labels for irregular sub-ms TimedeltaIndex plot (GH#18910) (pandas-dev#65991)
  TST: to_csv does not require escapechar for null byte (GH#47871) (pandas-dev#65995)
  TST: cut Series with NaN and integer bins (GH#55684) (pandas-dev#65998)
  TST: replace does not coerce np.nan to NaT (GH#48034) (pandas-dev#65999)
  TST: pd.NA preserved through Series.map for nullable/Arrow dtypes (GH#57390) (pandas-dev#66002)
  TST: read_json from binary/S3 stream with chunksize (GH#47659) (pandas-dev#66005)
  TST: .loc on MultiIndex with inf-bounded IntervalIndex level (GH#46699) (pandas-dev#66006)
  TST: read_json preserves precision of big-int string columns (GH#44684) (pandas-dev#66008)
  BUG: fix DataFrame.any/all(skipna=False) raising on nullable dtypes (pandas-dev#65711)
  BUG: Series.sum on overflowing timedelta64 raises OutOfBoundsTimedelta (pandas-devGH-43178) (pandas-dev#65926)
  BUG: TextReader() with no arguments segfaults (pandas-devGH-53131) (pandas-dev#65939)
  DOC: Add note about SQL Server temp table datetime precision loss (pandas-dev#62995) (pandas-dev#63623)
  DOC: correct diff result-dtype description (GH#57565) (pandas-dev#65947)
  TST: to_csv date_format honored for PeriodArray column (pandas-devGH-51621) (pandas-dev#65952)
  TST: groupby with datetime-parseable Series name (GH#51818) (pandas-dev#65953)
  TST: query/eval with a column named 'datetime' (pandas-devGH-35695) (pandas-dev#65967)
  TST: bar plot color maps per column for single-column frame (GH#18006) (pandas-dev#65971)
  TST: non-monotonic DatetimeIndex.get_loc raises KeyError for missing label (pandas-devGH-7827) (pandas-dev#65958)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug Reduction Operations sum, mean, min, max, etc. Timedelta Timedelta data type

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant