Skip to content
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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pandas/io/html.py
Original file line number Diff line number Diff line change
Expand Up @@ -897,7 +897,7 @@ def _parse(flavor, io, match, attrs, encoding, displayed_only, **kwargs):

try:
tables = p.parse_tables()
except Exception as caught:
except ValueError as caught:
# if `io` is an io-like object, check if it's seekable
# and try to rewind it before trying the next parser
if hasattr(io, "seekable") and io.seekable():
Expand Down
31 changes: 18 additions & 13 deletions pandas/io/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Copy link
Contributor

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?

Copy link
Member Author

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

return tools.to_datetime(parsed, errors="ignore")

else:
Copy link
Contributor

Choose a reason for hiding this comment

The 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.

Copy link
Member Author

Choose a reason for hiding this comment

The 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

Expand Down