Skip to content

Commit 6563e7c

Browse files
Fix BUG: overflow on pd.Timedelta(nanoseconds=) constructor
Add regression test
1 parent c5f0ebf commit 6563e7c

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

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

+2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
(1, 1),
1717
(np.int64(2), 2),
1818
(np.int32(3), 3),
19+
(Timedelta(1e10), 1e10),
20+
(Timedelta(nanoseconds=1e10), 1e10),
1921
],
2022
)
2123
def test_delta_to_nanoseconds(obj, expected):

0 commit comments

Comments
 (0)