Skip to content

Commit d6e9464

Browse files
committed
handle 7 digits
1 parent 85a1745 commit d6e9464

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

pandas/_libs/tslibs/timedeltas.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -688,7 +688,7 @@ cdef bint needs_nano_unit(int64_t ival, str item):
688688
# TODO: more performant way of doing this check?
689689
if ival % 1000 != 0:
690690
return True
691-
return re.search(r"\.\d{9}", item) or "ns" in item or "nano" in item
691+
return re.search(r"\.\d{7}", item) or "ns" in item or "nano" in item
692692

693693

694694
cpdef inline str parse_timedelta_unit(str unit):

pandas/tests/scalar/timedelta/test_constructors.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -717,5 +717,9 @@ def test_parsed_unit():
717717
td = Timedelta("1 Day 2:03:04.012345")
718718
assert td.unit == "us"
719719

720-
td = Timedelta("1 Day 2:03:04.012345123")
720+
td = Timedelta("1 Day 2:03:04.012345000")
721+
assert td.unit == "ns"
722+
723+
# 7 digits after the decimal
724+
td = Timedelta("1 Day 2:03:04.0123450")
721725
assert td.unit == "ns"

0 commit comments

Comments
 (0)