Skip to content

Commit 5c8adcf

Browse files
committed
BUG: fixing total_seconds for timedeltas smaller then 1 microsecond
1 parent 58b6e06 commit 5c8adcf

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

pandas/_libs/tslibs/conversion.pyx

+1-1
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@ cdef _TSObject convert_datetime_to_tsobject(datetime ts, tzinfo tz,
504504

505505
if obj.tzinfo is not None and not is_utc(obj.tzinfo):
506506
offset = get_utcoffset(obj.tzinfo, ts)
507-
obj.value -= int(offset.total_seconds() * 1e9)
507+
obj.value -= int(offset.total_seconds() * 1_000_000_000)
508508

509509
if isinstance(ts, ABCTimestamp):
510510
obj.value += <int64_t>ts.nanosecond

pandas/_libs/tslibs/timedeltas.pyx

+4
Original file line numberDiff line numberDiff line change
@@ -1520,6 +1520,10 @@ class Timedelta(_Timedelta):
15201520
div = other // self
15211521
return div, other - div * self
15221522

1523+
def total_seconds(self):
1524+
"""Total seconds in the duration."""
1525+
return self.value / 1_000_000_000
1526+
15231527

15241528
cdef bint is_any_td_scalar(object obj):
15251529
"""

0 commit comments

Comments
 (0)