Skip to content

Commit 9aaaf1b

Browse files
Fix BUG: overflow on pd.Timedelta(nanoseconds=) constructor (pandas-dev#32424)
1 parent fd8384e commit 9aaaf1b

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

doc/source/whatsnew/v1.1.0.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ Numeric
234234
Conversion
235235
^^^^^^^^^^
236236
- Bug in :class:`Series` construction from NumPy array with big-endian ``datetime64`` dtype (:issue:`29684`)
237-
-
237+
- Bug in :class:`Timedelta` construction with large nanoseconds keyword value (:issue:`34202`)
238238
-
239239

240240
Strings

pandas/_libs/tslibs/timedeltas.pyx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1198,7 +1198,7 @@ class Timedelta(_Timedelta):
11981198

11991199
kwargs = {key: _to_py_int_float(kwargs[key]) for key in kwargs}
12001200

1201-
nano = np.timedelta64(kwargs.pop('nanoseconds', 0), 'ns')
1201+
nano = convert_to_timedelta64(kwargs.pop('nanoseconds', 0), 'ns')
12021202
try:
12031203
value = nano + convert_to_timedelta64(timedelta(**kwargs),
12041204
'ns')

pandas/tests/tslibs/test_timedeltas.py

+6
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,9 @@ def test_delta_to_nanoseconds_error():
2828

2929
with pytest.raises(TypeError, match="<class 'numpy.ndarray'>"):
3030
delta_to_nanoseconds(obj)
31+
32+
33+
def test_huge_nanoseconds_overflow():
34+
# GH 32402
35+
assert delta_to_nanoseconds(Timedelta(1e10)) == 1e10
36+
assert delta_to_nanoseconds(Timedelta(nanoseconds=1e10)) == 1e10

0 commit comments

Comments
 (0)