Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit eda7b16

Browse files
committed
TST Add test parametrization
Tests changed: - `test_affinity_propagation_precomputed_with_sparse_input` - `test_sparse_input_for_predict` - `test_sparse_input_for_fit_predict` Signed-off-by: Julien Jerphanion <[email protected]>
1 parent 2b27852 commit eda7b16

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

sklearn/cluster/tests/test_affinity_propagation.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from sklearn.exceptions import ConvergenceWarning, NotFittedError
1616
from sklearn.metrics import euclidean_distances
1717
from sklearn.utils._testing import assert_allclose, assert_array_equal
18+
from sklearn.utils.fixes import CSR_CONTAINERS
1819

1920
n_clusters = 3
2021
centers = np.array([[1, 1], [-1, -1], [1, -1]]) + 10
@@ -104,10 +105,11 @@ def test_affinity_propagation_affinity_shape():
104105
affinity_propagation(S[:, :-1])
105106

106107

107-
def test_affinity_propagation_precomputed_with_sparse_input():
108+
@pytest.mark.parametrize("csr_container", CSR_CONTAINERS)
109+
def test_affinity_propagation_precomputed_with_sparse_input(csr_container):
108110
err_msg = "A sparse matrix was passed, but dense data is required"
109111
with pytest.raises(TypeError, match=err_msg):
110-
AffinityPropagation(affinity="precomputed").fit(csr_matrix((3, 3)))
112+
AffinityPropagation(affinity="precomputed").fit(csr_container((3, 3)))
111113

112114

113115
def test_affinity_propagation_predict(global_random_seed, global_dtype):
@@ -287,20 +289,22 @@ def test_correct_clusters(global_dtype):
287289
assert_array_equal(afp.labels_, expected)
288290

289291

290-
def test_sparse_input_for_predict():
292+
@pytest.mark.parametrize("csr_container", CSR_CONTAINERS)
293+
def test_sparse_input_for_predict(csr_container):
291294
# Test to make sure sparse inputs are accepted for predict
292295
# (non-regression test for issue #20049)
293296
af = AffinityPropagation(affinity="euclidean", random_state=42)
294297
af.fit(X)
295-
labels = af.predict(csr_matrix((2, 2)))
298+
labels = af.predict(csr_container((2, 2)))
296299
assert_array_equal(labels, (2, 2))
297300

298301

299-
def test_sparse_input_for_fit_predict():
302+
@pytest.mark.parametrize("csr_container", CSR_CONTAINERS)
303+
def test_sparse_input_for_fit_predict(csr_container):
300304
# Test to make sure sparse inputs are accepted for fit_predict
301305
# (non-regression test for issue #20049)
302306
af = AffinityPropagation(affinity="euclidean", random_state=42)
303307
rng = np.random.RandomState(42)
304-
X = csr_matrix(rng.randint(0, 2, size=(5, 5)))
308+
X = csr_container(rng.randint(0, 2, size=(5, 5)))
305309
labels = af.fit_predict(X)
306310
assert_array_equal(labels, (0, 1, 1, 2, 3))

0 commit comments

Comments
 (0)