Skip to content

Commit 23d69ec

Browse files
committed
SparseArray error workaround
1 parent 580610b commit 23d69ec

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

sklbench/datasets/downloaders.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,11 @@ def fetch_and_correct_openml(
109109
if isinstance(y, pd.Series):
110110
if isinstance(y.dtype, pd.CategoricalDtype):
111111
y = y.cat.codes
112-
y = y.values
112+
# Use to_numpy() for sparse arrays to densify them, otherwise use values
113+
if pd.api.types.is_sparse(y):
114+
y = y.to_numpy()
115+
else:
116+
y = y.values
113117
elif not isinstance(y, np.ndarray):
114118
raise ValueError(f'Unknown y type "{type(y)}" returned from openml')
115119

0 commit comments

Comments
 (0)