Skip to content

Commit dcf88e9

Browse files
TST Extend tests for scipy.sparse.*array in test_encoders.py (scikit-learn#27289)
1 parent 5dbb8f5 commit dcf88e9

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

sklearn/preprocessing/tests/test_encoders.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
assert_allclose,
1313
assert_array_equal,
1414
)
15+
from sklearn.utils.fixes import CSR_CONTAINERS
1516

1617

1718
def test_one_hot_encoder_sparse_dense():
@@ -1761,13 +1762,14 @@ def test_ordinal_encoder_handle_missing_and_unknown(X, expected_X_trans, X_test)
17611762
assert_allclose(oe.transform(X_test), [[-1.0]])
17621763

17631764

1764-
def test_ordinal_encoder_sparse():
1765+
@pytest.mark.parametrize("csr_container", CSR_CONTAINERS)
1766+
def test_ordinal_encoder_sparse(csr_container):
17651767
"""Check that we raise proper error with sparse input in OrdinalEncoder.
17661768
Non-regression test for:
17671769
https://github.com/scikit-learn/scikit-learn/issues/19878
17681770
"""
17691771
X = np.array([[3, 2, 1], [0, 1, 1]])
1770-
X_sparse = sparse.csr_matrix(X)
1772+
X_sparse = csr_container(X)
17711773

17721774
encoder = OrdinalEncoder()
17731775

@@ -1778,7 +1780,7 @@ def test_ordinal_encoder_sparse():
17781780
encoder.fit_transform(X_sparse)
17791781

17801782
X_trans = encoder.fit_transform(X)
1781-
X_trans_sparse = sparse.csr_matrix(X_trans)
1783+
X_trans_sparse = csr_container(X_trans)
17821784
with pytest.raises(TypeError, match=err_msg):
17831785
encoder.inverse_transform(X_trans_sparse)
17841786

0 commit comments

Comments
 (0)