-
-
Notifications
You must be signed in to change notification settings - Fork 25.8k
ENH allows to overwrite read_csv parameter in fetch_openml #25488
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
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -419,6 +419,7 @@ def _load_arff_response( | |
md5_checksum: str, | ||
n_retries: int = 3, | ||
delay: float = 1.0, | ||
read_csv_kwargs: Optional[Dict] = None, | ||
): | ||
"""Load the ARFF data associated with the OpenML URL. | ||
|
||
|
@@ -461,6 +462,12 @@ def _load_arff_response( | |
md5_checksum : str | ||
The MD5 checksum provided by OpenML to check the data integrity. | ||
|
||
read_csv_kwargs : dict, default=None | ||
Keyword arguments to pass to `pandas.read_csv`. It allows to overwrite | ||
the default options. | ||
|
||
.. versionadded:: 1.3 | ||
|
||
Returns | ||
------- | ||
X : {ndarray, sparse matrix, dataframe} | ||
|
@@ -503,6 +510,7 @@ def _load_arff_response( | |
feature_names_to_select=feature_names_to_select, | ||
target_names_to_select=target_names_to_select, | ||
shape=shape, | ||
read_csv_kwargs=read_csv_kwargs, | ||
) | ||
|
||
return X, y, frame, categories | ||
|
@@ -522,6 +530,7 @@ def _download_data_to_bunch( | |
n_retries: int = 3, | ||
delay: float = 1.0, | ||
parser: str, | ||
read_csv_kwargs: Optional[Dict] = None, | ||
): | ||
"""Download ARFF data, load it to a specific container and create to Bunch. | ||
|
||
|
@@ -568,6 +577,21 @@ def _download_data_to_bunch( | |
parser : {"liac-arff", "pandas"} | ||
The parser used to parse the ARFF file. | ||
|
||
read_csv_kwargs : dict, default=None | ||
Keyword arguments to pass to `pandas.read_csv`. It allows to overwrite | ||
the default options. Internally, we used the default parameters of | ||
:func:`pandas.read_csv` except for the following parameters: | ||
|
||
- `header`: set to `None` | ||
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. Should this be in |
||
- `na_values`: set to `["?"]` | ||
- `comment`: set to `#` | ||
- `quotechar`: set to `"` (double quote) | ||
- `names`: set to the list of column names given by OpenML | ||
- `dtypes`: set to the list provided by OpenML | ||
- `skipinitialspace`: set to `True` | ||
|
||
.. versionadded:: 1.3 | ||
|
||
Returns | ||
------- | ||
data : :class:`~sklearn.utils.Bunch` | ||
|
@@ -619,6 +643,7 @@ def _download_data_to_bunch( | |
md5_checksum=md5_checksum, | ||
n_retries=n_retries, | ||
delay=delay, | ||
read_csv_kwargs=read_csv_kwargs, | ||
) | ||
|
||
return Bunch( | ||
|
@@ -687,6 +712,7 @@ def fetch_openml( | |
n_retries: int = 3, | ||
delay: float = 1.0, | ||
parser: Optional[str] = "warn", | ||
read_csv_kwargs: Optional[Dict] = None, | ||
): | ||
"""Fetch dataset from openml by name or dataset id. | ||
|
||
|
@@ -791,6 +817,12 @@ def fetch_openml( | |
warning. Therefore, an `ImportError` will be raised from 1.4 if | ||
the dataset is dense and pandas is not installed. | ||
|
||
read_csv_kwargs : dict, default=None | ||
Keyword arguments passed to `pandas.read_csv` when loading the data | ||
from a ARFF file. It can allows to overwrite some default parameters. | ||
|
||
.. versionadded:: 1.3 | ||
|
||
Returns | ||
------- | ||
data : :class:`~sklearn.utils.Bunch` | ||
|
@@ -1054,6 +1086,7 @@ def fetch_openml( | |
n_retries=n_retries, | ||
delay=delay, | ||
parser=parser_, | ||
read_csv_kwargs=read_csv_kwargs, | ||
) | ||
|
||
if return_X_y: | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Currently, if there is an exception while reading the data, one would need to enter a debugger to find out where the file is and what the
read_csv_kwargs
are. I think it would be helpful reraise an exception that outputs theread_csv_kwargs
andgzip_file
to help with debugging the issue.