8000 TST Replaces pytest.warns(None) in test_voting (#22949) · thomasjpfan/scikit-learn@8e65d0c · GitHub
[go: up one dir, main page]

Skip to content

Commit 8e65d0c

Browse files
TST Replaces pytest.warns(None) in test_voting (scikit-learn#22949)
Co-authored-by: Thomas J. Fan <thomasjpfan@gmail.com>
1 parent 271d450 commit 8e65d0c

File tree

1 file changed

+6
-16
lines changed

1 file changed

+6
-16
lines changed

sklearn/ensemble/tests/test_voting.py

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -426,10 +426,8 @@ def test_set_estimator_drop():
426426
voting="hard",
427427
weights=[1, 1, 0.5],
428428
)
429-
with pytest.warns(None) as record:
430-
eclf2.set_params(rf="drop").fit(X, y)
429+
eclf2.set_params(rf="drop").fit(X, y)
431430

432-
assert not [w.message for w in record]
433431
assert_array_equal(eclf1.predict(X), eclf2.predict(X) 8000 )
434432

435433
assert dict(eclf2.estimators)["rf"] == "drop"
@@ -440,17 +438,13 @@ def test_set_estimator_drop():
440438
assert eclf2.get_params()["rf"] == "drop"
441439

442440
eclf1.set_params(voting="soft").fit(X, y)
443-
with pytest.warns(None) as record:
444-
eclf2.set_params(voting="soft").fit(X, y)
441+
eclf2.set_params(voting="soft").fit(X, y)
445442

446-
assert not [w.message for w in record]
447443
assert_array_equal(eclf1.predict(X), eclf2.predict(X))
448444
assert_array_almost_equal(eclf1.predict_proba(X), eclf2.predict_proba(X))
449445
msg = "All estimators are dropped. At least one is required"
450-
with pytest.warns(None) as record:
451-
with pytest.raises(ValueError, match=msg):
452-
eclf2.set_params(lr="drop", rf="drop", nb="drop").fit(X, y)
453-
assert not [w.message for w in record]
446+
with pytest.raises(ValueError, match=msg):
447+
eclf2.set_params(lr="drop", rf="drop", nb="drop").fit(X, y)
454448

455449
# Test soft voting transform
456450
X1 = np.array([[1], [2]])
@@ -468,9 +462,7 @@ def test_set_estimator_drop():
468462
weights=[1, 0.5],
469463
flatten_transform=False,
470464
)
471-
with pytest.warns(None) as record:
472-
eclf2.set_params(rf="drop").fit(X1, y1)
473-
assert not [w.message for w in record]
465+
eclf2.set_params(rf="drop").fit(X1, y1)
474466
assert_array_almost_equal(
475467
eclf1.transform(X1),
476468
np.array([[[0.7, 0.3], [0.3, 0.7]], [[1.0, 0.0], [0.0, 1.0]]]),
@@ -560,9 +552,7 @@ def test_none_estimator_with_weights(X, y, voter):
560552
voter = clone(voter)
561553
voter.fit(X, y, sample_weight=np.ones(y.shape))
562554
voter.set_params(lr="drop")
563-
with pytest.warns(None) as record:
564-
voter.fit(X, y, sample_weight=np.ones(y.shape))
565-
assert not [w.message for w in record]
555+
voter.fit(X, y, sample_weight=np.ones(y.shape))
566556
y_pred = voter.predict(X)
567557
assert y_pred.shape == y.shape
568558

0 commit comments

Comments
 (0)
0