Skip to content

Commit cc478c4

Browse files
authored
BUG guess_Datetime_format doesn't guess 27.03.2003 14:55:00.000 (#50319)
* fix parsing * stricter regex Co-authored-by: MarcoGorelli <>
1 parent 49ceb1b commit cc478c4

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

pandas/_libs/tslibs/parsing.pyx

+3-1
Original file line numberDiff line numberDiff line change
@@ -1016,9 +1016,11 @@ def guess_datetime_format(dt_str: str, bint dayfirst=False) -> str | None:
10161016

10171017
cdef str _fill_token(token: str, padding: int):
10181018
cdef str token_filled
1019-
if "." not in token:
1019+
if re.search(r"\d+\.\d+", token) is None:
1020+
# For example: 98
10201021
token_filled = token.zfill(padding)
10211022
else:
1023+
# For example: 00.123
10221024
seconds, nanoseconds = token.split(".")
10231025
seconds = f"{int(seconds):02d}"
10241026
# right-pad so we get nanoseconds, then only take

pandas/tests/tslibs/test_parsing.py

+1
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ def test_parsers_month_freq(date_str, expected):
179179
("2011-12-30 00:00:00.000000", "%Y-%m-%d %H:%M:%S.%f"),
180180
("Tue 24 Aug 2021 01:30:48 AM", "%a %d %b %Y %H:%M:%S %p"),
181181
("Tuesday 24 Aug 2021 01:30:48 AM", "%A %d %b %Y %H:%M:%S %p"),
182+
("27.03.2003 14:55:00.000", "%d.%m.%Y %H:%M:%S.%f"), # GH50317
182183
],
183184
)
184185
def test_guess_datetime_format_with_parseable_formats(string, fmt):

0 commit comments

Comments
 (0)