Skip to content

Commit 32e3975

Browse files
authored
TST Extend tests for scipy.sparse.*array in sklearn/preprocessing/tests/test_common.py (scikit-learn#27164)
1 parent 335c2d2 commit 32e3975

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed

sklearn/preprocessing/tests/test_common.py

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import numpy as np
44
import pytest
5-
from scipy import sparse
65

76
from sklearn.base import clone
87
from sklearn.datasets import load_iris
@@ -22,6 +21,15 @@
2221
scale,
2322
)
2423
from sklearn.utils._testing import assert_allclose, assert_array_equal
24+
from sklearn.utils.fixes import (
25+
BSR_CONTAINERS,
26+
COO_CONTAINERS,
27+
CSC_CONTAINERS,
28+
CSR_CONTAINERS,
29+
DIA_CONTAINERS,
30+
DOK_CONTAINERS,
31+
LIL_CONTAINERS,
32+
)
2533

2634
iris = load_iris()
2735

@@ -113,19 +121,19 @@ def test_missing_value_handling(
113121
Xt_dense = est_dense.fit(X_train).transform(X_test)
114122
Xt_inv_dense = est_dense.inverse_transform(Xt_dense)
115123

116-
for sparse_constructor in (
117-
sparse.csr_matrix,
118-
sparse.csc_matrix,
119-
sparse.bsr_matrix,
120-
sparse.coo_matrix,
121-
sparse.dia_matrix,
122-
sparse.dok_matrix,
123-
sparse.lil_matrix,
124+
for sparse_container in (
125+
BSR_CONTAINERS
126+
+ COO_CONTAINERS
127+
+ CSC_CONTAINERS
128+
+ CSR_CONTAINERS
129+
+ DIA_CONTAINERS
130+
+ DOK_CONTAINERS
131+
+ LIL_CONTAINERS
124132
):
125133
# check that the dense and sparse inputs lead to the same results
126134
# precompute the matrix to avoid catching side warnings
127-
X_train_sp = sparse_constructor(X_train)
128-
X_test_sp = sparse_constructor(X_test)
135+
X_train_sp = sparse_container(X_train)
136+
X_test_sp = sparse_container(X_test)
129137
with warnings.catch_warnings():
130138
warnings.simplefilter("ignore", PendingDeprecationWarning)
131139
warnings.simplefilter("error", RuntimeWarning)

0 commit comments

Comments
 (0)