-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
CI: avoid guess_datetime_format
failure on 29th of Feburary
#57674
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 |
---|---|---|
|
@@ -936,8 +936,7 @@ def guess_datetime_format(dt_str: str, bint dayfirst=False) -> str | None: | |
datetime_attrs_to_format.remove(day_attribute_and_format) | ||
datetime_attrs_to_format.insert(0, day_attribute_and_format) | ||
|
||
# same default used by dateutil | ||
default = datetime.now().replace(hour=0, minute=0, second=0, microsecond=0) | ||
default = datetime(1970, 1, 1) | ||
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 fail to understand what's going on. Surely happy to get this merged if it fixes the problem and you understand what's going on. The root problem seems to be that
I didn't debug it, I guess you did, but I can't see why in the implementation it should make a difference. As said, if you are confident that this is a good solution and the algorithm is relivable happy to get this merged. But seems like there is a bug in the algorithm below we are not preventing/hacking, no? 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 seems like there's something in pandas' vendored code which makes 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. @datapythonista - currently in main we take today's date, replace it with the bits that the user passed, and then check if it's a valid date. E.g. "2002" on 2/29 becomes "2002-02-29" which is not a valid date. From this we conclude we've somehow guessed wrong. 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. Thanks both. I see, I assumed In any case I think the fix is fine, a function to get the format from a partial date is surely not going to be perfect anyway. |
||
try: | ||
parsed_datetime = dateutil_parse( | ||
dt_str, | ||
|
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.
the guessed format is checked explicitly against the input:
pandas/pandas/_libs/tslibs/parsing.pyx
Lines 1050 to 1061 in 7bdb6d8
so this should be safe
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.
worth adding a comment about why this default was chosen?
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.
sure, thanks