Skip to content

Commit 148eda7

Browse files
author
MarcoGorelli
committed
guess nanoseconds
1 parent 1e20390 commit 148eda7

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

pandas/_libs/tslibs/parsing.pyx

+7-4
Original file line numberDiff line numberDiff line change
@@ -1051,10 +1051,13 @@ def guess_datetime_format(dt_str: str, bint dayfirst=False) -> str | None:
10511051
if '.' not in tokens[i]:
10521052
token_filled = tokens[i].zfill(padding)
10531053
else:
1054-
seconds, milliseconds = tokens[i].split('.')
1055-
seconds = seconds.zfill(2)
1056-
millisecond = milliseconds.zfill(6)
1057-
token_filled = f'{seconds}.{milliseconds}'
1054+
seconds, nanoseconds = tokens[i].split('.')
1055+
seconds = f'{int(seconds):02d}'
1056+
# right-pad so we get nanoseconds, then only take
1057+
# first 6 digits (microseconds) as stdlib datetime
1058+
# doesn't support nanoseconds
1059+
nanoseconds = nanoseconds.ljust(9, '0')[:6]
1060+
token_filled = f'{seconds}.{nanoseconds}'
10581061
if token_format is None and token_filled == parsed_formatted:
10591062
format_guess[i] = attr_format
10601063
tokens[i] = token_filled

0 commit comments

Comments
 (0)