-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG guess_Datetime_format doesn't guess 27.03.2003 14:55:00.000 #50319
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -1016,9 +1016,11 @@ def guess_datetime_format(dt_str: str, bint dayfirst=False) -> str | None: | |||||
|
||||||
cdef str _fill_token(token: str, padding: int): | ||||||
cdef str token_filled | ||||||
if "." not in token: | ||||||
if re.search(r"\d*\.\d+", token) is None: | ||||||
# For example: 98 | ||||||
token_filled = token.zfill(padding) | ||||||
else: | ||||||
# For example: 00.123 | ||||||
seconds, nanoseconds = token.split(".") | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is there a risk that this raises if there is a "." but not the regex? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yup, you'd get In [6]: token = '.'
In [7]: seconds, nanoseconds = token.split(".")
In [8]: seconds = f"{int(seconds):02d}"
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
Cell In [8], line 1
----> 1 seconds = f"{int(seconds):02d}"
ValueError: invalid literal for int() with base 10: '' which is what happens in the string in the linked issue ( There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i take it this is caught elsewhere so isnt a problem? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah, if the padding was pandas/pandas/_libs/tslibs/parsing.pyx Lines 945 to 946 in f7979be
it wouldn't match |
||||||
seconds = f"{int(seconds):02d}" | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. previously,
was failing if If we make the check more precise, then we avoid that issue |
||||||
# right-pad so we get nanoseconds, then only take | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is the leading
\d*
needed here?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
\d+
would be better actually, thanksThis is for when it corresponds with the
%S.%f
directive