Skip to content

Commit

Permalink
TST Fix openml parser implementation for pandas-dev (scikit-learn#26386)
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasjpfan committed May 23, 2023
1 parent e956876 commit edfdbd0
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
3 changes: 3 additions & 0 deletions doc/whats_new/v1.3.rst
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,9 @@ Changelog
is deprecated and will be removed in v1.5.
:pr:`25784` by :user:`Jérémie du Boisberranger`.

- |Fix| :func:`datasets.fetch_openml` returns improved data types when
`as_frame=True` and `parser="liac-arff"`. :pr:`26386` by `Thomas Fan`_.

:mod:`sklearn.decomposition`
............................

Expand Down
5 changes: 5 additions & 0 deletions sklearn/datasets/_arff_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,11 @@ def _io_to_generator(gzip_file):
dfs.append(
pd.DataFrame(data, columns=columns_names, copy=False)[columns_to_keep]
)
# dfs[0] contains only one row, which may not have enough data to infer to
# column's dtype. Here we use `dfs[1]` to configure the dtype in dfs[0]
if len(dfs) >= 2:
dfs[0] = dfs[0].astype(dfs[1].dtypes)

frame = pd.concat(dfs, ignore_index=True)
del dfs, first_df

Expand Down
2 changes: 1 addition & 1 deletion sklearn/datasets/tests/test_openml.py
Original file line number Diff line number Diff line change
Expand Up @@ -925,7 +925,7 @@ def datasets_missing_values():
# with casting it will be transformed to either float or Int64
(40966, "pandas", 1, 77, 0),
# titanic
(40945, "liac-arff", 3, 5, 0),
(40945, "liac-arff", 3, 6, 0),
(40945, "pandas", 3, 3, 3),
],
)
Expand Down

0 comments on commit edfdbd0

Please sign in to comment.