-
-
Notifications
You must be signed in to change notification settings - Fork 18.1k
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
CLN: catch less in pd.io #28862
CLN: catch less in pd.io #28862
Changes from all commits
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 |
---|---|---|
|
@@ -3271,24 +3271,29 @@ def converter(*date_cols): | |
) | ||
else: | ||
try: | ||
result = tools.to_datetime( | ||
date_parser(*date_cols), errors="ignore", cache=cache_dates | ||
) | ||
if isinstance(result, datetime.datetime): | ||
raise Exception("scalar parser") | ||
return result | ||
parsed_cols = date_parser(*date_cols) | ||
if isinstance(parsed_cols, datetime.datetime): | ||
raise TypeError("scalar parser") | ||
except Exception: | ||
# Since `date_parser` is user-provided, we can't guess | ||
# what it might raise. | ||
dcs = parsing._concat_date_cols(date_cols) | ||
try: | ||
return tools.to_datetime( | ||
parsing.try_parse_dates( | ||
parsing._concat_date_cols(date_cols), | ||
parser=date_parser, | ||
dayfirst=dayfirst, | ||
), | ||
errors="ignore", | ||
parsed = parsing.try_parse_dates( | ||
dcs, parser=date_parser, dayfirst=dayfirst | ||
) | ||
except Exception: | ||
# Since `date_parser` is user-provided, we can't guess | ||
# what it might raise. | ||
return generic_parser(date_parser, *date_cols) | ||
else: | ||
return tools.to_datetime(parsed, errors="ignore") | ||
|
||
else: | ||
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. this looks like a new path, is it actually hit? this code seems to have gotten more complex as well. 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. The to_datetime call below corresponds to the to_datetime call on 3274 in master. This is just moving it outside of the try/except. |
||
result = tools.to_datetime( | ||
parsed_cols, errors="ignore", cache=cache_dates | ||
) | ||
return result | ||
|
||
return converter | ||
|
||
|
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.
do we need this or the bottom else at all?
IOW if you just remove these and have the last line of the function do what you do on 3293 right now it seems cleaner?
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.
this isnt obvious, largely because we are dealing with a user-provided
date_parser
function. ill take another look