Skip to content

Commit a4ccd56

Browse files
Fail graciously on SciPy sparray inputs
Graciously means using scikit-learn's `check_array` with the parameter `accept_sparse=False`.
1 parent b83af40 commit a4ccd56

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

khiops/sklearn/tables.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,11 +166,27 @@ def __init__(self, X, y=None, categorical_target=True, key=None):
166166
y,
167167
categorical_target=categorical_target,
168168
)
169-
# A sparse matrix
169+
# A scipy.sparse.spmatrix
170170
elif isinstance(X, sp.spmatrix):
171171
self._init_tables_from_sparse_matrix(
172172
X, y, categorical_target=categorical_target
173173
)
174+
# Special rejection for scipy.sparse.sparray (to pass the sklearn tests)
175+
# Note: We don't use scipy.sparse.sparray because it is not implemented in scipy
176+
# 1.10 which is the latest supporting py3.8
177+
elif isinstance(
178+
X,
179+
(
180+
sp.bsr_array,
181+
sp.coo_array,
182+
sp.csc_array,
183+
sp.csr_array,
184+
sp.dia_array,
185+
sp.dok_array,
186+
sp.lil_array,
187+
),
188+
):
189+
check_array(X, accept_sparse=False)
174190
# A tuple spec
175191
elif isinstance(X, tuple):
176192
warnings.warn(

0 commit comments

Comments
 (0)