Skip to content

Commit a615d43

Browse files
Update pandas/_libs/tslibs/timedeltas.pyx
Co-authored-by: Joris Van den Bossche <jorisvandenbossche@gmail.com>
1 parent d6e9464 commit a615d43

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

pandas/_libs/tslibs/timedeltas.pyx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -683,7 +683,14 @@ cdef timedelta_from_spec(object number, object frac, object unit):
683683
cdef bint needs_nano_unit(int64_t ival, str item):
684684
"""
685685
Check if a passed string `item` needs to be stored with nano unit or can
686-
use microsecond instead.
686+
use microsecond instead. Needs nanoseconds if:
687+
688+
- if the parsed value in nanoseconds has sub-microseconds content -> certainly
689+
needs nano
690+
- if the seconds part in the string contains more than 6 decimals, i.e. has
691+
trailing zeros beyond the microsecond part (e.g. "0.123456000 s") -> treat
692+
as nano for consistency
693+
- if the string explicitly contains an entry for nanoseconds (e.g. "1000 ns")
687694
"""
688695
# TODO: more performant way of doing this check?
689696
if ival % 1000 != 0:

0 commit comments

Comments
 (0)