Skip to content

FIX possible UnboundLocalError in fetch_openml #26236

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

Merged
merged 1 commit into from
Apr 20, 2023
Merged
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
28 changes: 15 additions & 13 deletions sklearn/datasets/_openml.py
Original file line number Diff line number Diff line change
Expand Up @@ -519,19 +519,21 @@ def _open_url_and_load_gzip_file(url, data_home, n_retries, delay, arff_params):
url, data_home, n_retries, delay, arff_params
)
except Exception as exc:
if parser == "pandas":
from pandas.errors import ParserError

if isinstance(exc, ParserError):
# A parsing error could come from providing the wrong quotechar
# to pandas. By default, we use a double quote. Thus, we retry
# with a single quote before to raise the error.
arff_params["read_csv_kwargs"] = {"quotechar": "'"}
X, y, frame, categories = _open_url_and_load_gzip_file(
url, data_home, n_retries, delay, arff_params
)
else:
raise
if parser != "pandas":
raise

from pandas.errors import ParserError

if not isinstance(exc, ParserError):
raise

# A parsing error could come from providing the wrong quotechar
# to pandas. By default, we use a double quote. Thus, we retry
# with a single quote before to raise the error.
arff_params["read_csv_kwargs"] = {"quotechar": "'"}
X, y, frame, categories = _open_url_and_load_gzip_file(
url, data_home, n_retries, delay, arff_params
)

return X, y, frame, categories

Expand Down