Skip to content

Commit 8f9fca0

Browse files
committed
Merge branch 'td-string-parse' of github.com:jbrockmendel/pandas into td-string-parse
2 parents 506db5c + a615d43 commit 8f9fca0

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

0 commit comments

Comments
 (0)