8000 raise DeprecationWarnings and FutureWarnings as errors (#11570) · scikit-learn/scikit-learn@8e2c2aa · GitHub
[go: up one dir, main page]

Skip to content

Commit 8e2c2aa

Browse files
authored
raise DeprecationWarnings and FutureWarnings as errors (#11570)
Towards #11252. In the end we'd like to make these errors so we can keep this cleaner in the future.
1 parent 9caa982 commit 8e2c2aa

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+292
-124
lines changed

setup.cfg

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ addopts =
88
--doctest-modules
99
--disable-pytest-warnings
1010
-rs
11+
filterwarnings =
12+
error::DeprecationWarning
13+
error::FutureWarning
1114

1215
[wheelhouse_uploader]
1316
artifact_indexes=

sklearn/cluster/tests/test_hierarchical.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
# License: BSD 3 clause
88
from tempfile import mkdtemp
99
import shutil
10+
import pytest
1011
from functools import partial
1112

1213
import numpy as np
@@ -142,6 +143,8 @@ def test_agglomerative_clustering_wrong_arg_memory():
142143
assert_raises(ValueError, clustering.fit, X)
143144

144145

146+
@pytest.mark.filterwarnings("ignore:the behavior of nmi will "
147+
"change in version 0.22")
145148
def test_agglomerative_clustering():
146149
# Check that we obtain the correct number of clusters with
147150
# agglomerative clustering.
@@ -250,6 +253,8 @@ def test_ward_agglomeration():
250253
assert_raises(ValueError, agglo.fit, X[:0])
251254

252255

256+
@pytest.mark.filterwarnings("ignore:the behavior of nmi will "
257+
"change in version 0.22")
253258
def test_single_linkage_clustering():
254259
# Check that we get the correct result in two emblematic cases
255260
moons, moon_labels = make_moons(noise=0.05, random_state=42)
@@ -311,6 +316,8 @@ def test_scikit_vs_scipy():
311316
assert_raises(ValueError, _hc_cut, n_leaves + 1, children, n_leaves)
312317

313318

319+
@pytest.mark.filterwarnings("ignore:the behavior of nmi will "
320+
"change in version 0.22")
314321
def test_identical_points():
315322
# Ensure identical points are handled correctly when using mst with
316323
# a sparse connectivity matrix

sklearn/covariance/tests/test_graphical_lasso.py

Lines changed: 3 additions & 3 deletions
F987
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import numpy as np
66
from scipy import linalg
7+
import pytest
78

89
from sklearn.utils.testing import assert_array_almost_equal
910
from sklearn.utils.testing import assert_array_less
@@ -151,6 +152,5 @@ def test_deprecated_grid_scores(random_state=1):
151152
"0.19 and will be removed in 0.21. Use "
152153
"``grid_scores_`` instead")
153154

154-
assert_warns_message(DeprecationWarning, depr_message,
155-
lambda: graphical_lasso.grid_scores)
156-
assert_equal(graphical_lasso.grid_scores, graphical_lasso.grid_scores_)
155+
with pytest.warns(DeprecationWarning, match=depr_message):
156+
assert_equal(graphical_lasso.grid_scores, graphical_lasso.grid_scores_)

sklearn/decomposition/tests/test_dict_learning.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ def test_dict_learning_overcomplete():
5858
assert_true(dico.components_.shape == (n_components, n_features))
5959

6060

61+
@ignore_warnings(category=DeprecationWarning) # positive lars deprecated 0.22
6162
@pytest.mark.parametrize("transform_algorithm", [
6263
"lasso_lars",
6364
"lasso_cd",
@@ -170,6 +171,7 @@ def test_dict_learning_online_shapes():
170171
assert_equal(np.dot(code, dictionary).shape, X.shape)
171172

172173

174+
@ignore_warnings(category=DeprecationWarning) # positive lars deprecated 0.22
173175
@pytest.mark.parametrize("transform_algorithm", [
174176
"lasso_lars",
175177
"lasso_cd",
@@ -306,6 +308,7 @@ def test_sparse_encode_shapes():
306308
assert_equal(code.shape, (n_samples, n_components))
307309

308310

311+
@ignore_warnings(category=DeprecationWarning) # positive lars deprecated 0.22
309312
@pytest.mark.parametrize("positive", [
310313
False,
311314
True,

sklearn/decomposition/tests/test_kernel_pca.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import numpy as np
22
import scipy.sparse as sp
3+
import pytest
34

45
from sklearn.utils.testing import (assert_array_almost_equal, assert_less,
56
assert_equal, assert_not_equal,
6-
assert_raises)
7+
assert_raises, ignore_warnings)
78

89
from sklearn.decomposition import PCA, KernelPCA
910
from sklearn.datasets import make_circles
@@ -172,6 +173,7 @@ def test_kernel_pca_invalid_kernel():
172173
assert_raises(ValueError, kpca.fit, X_fit)
173174

174175

176+
@pytest.mark.filterwarnings('ignore: The default of the `iid`') # 0.22
175177
def test_gridsearch_pipeline():
176178
# Test if we can do a grid-search to find parameters to separate
177179
# circles with a perceptron model.
@@ -186,6 +188,7 @@ def test_gridsearch_pipeline():
186188
assert_equal(grid_search.best_score_, 1)
187189

188190

191+
@pytest.mark.filterwarnings('ignore: The default of the `iid`') # 0.22
189192
def test_gridsearch_pipeline_precomputed():
190193
# Test if we can do a grid-search to find parameters to separate
191194
# circles with a perceptron model using a precomputed kernel.

sklearn/ensemble/forest.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -944,16 +944,17 @@ class labels (multi-output problem).
944944
>>> X, y = make_classification(n_samples=1000, n_features=4,
945945
... n_informative=2, n_redundant=0,
946946
... random_state=0, shuffle=False)
947-
>>> clf = RandomForestClassifier(max_depth=2, random_state=0)
947+
>>> clf = RandomForestClassifier(n_estimators=100, max_depth=2,
948+
... random_state=0)
948949
>>> clf.fit(X, y)
949950
RandomForestClassifier(bootstrap=True, class_weight=None, criterion='gini',
950951
max_depth=2, max_features='auto', max_leaf_nodes=None,
951952
min_impurity_decrease=0.0, min_impurity_split=None,
952953
min_samples_leaf=1, min_samples_split=2,
953-
min_weight_fraction_leaf=0.0, n_estimators=10, n_jobs=1,
954+
min_weight_fraction_leaf=0.0, n_estimators=100, n_jobs=1,
954955
oob_score=False, random_state=0, verbose=0, warm_start=False)
955956
>>> print(clf.feature_importances_)
956-
[0.17287856 0.80608704 0.01884792 0.00218648]
957+
[0.14205973 0.76664038 0.0282433 0.06305659]
957958
>>> print(clf.predict([[0, 0, 0, 0]]))
958959
[1]
959960
@@ -1188,18 +1189,19 @@ class RandomForestRegressor(ForestRegressor):
11881189
>>>
11891190
>>> X, y = make_regression(n_features=4, n_informative=2,
11901191
... random_state=0, shuffle=False)
1191-
>>> regr = RandomForestRegressor(max_depth=2, random_state=0)
1192+
>>> regr = RandomForestRegressor(max_depth=2, random_state=0,
1193+
... n_estimators=100)
11921194
>>> regr.fit(X, y)
11931195
RandomForestRegressor(bootstrap=True, criterion='mse', max_depth=2,
11941196
max_features='auto', max_leaf_nodes=None,
11951197
min_impurity_decrease=0.0, min_impurity_split=None,
11961198
min_samples_leaf=1, min_samples_split=2,
1197-
min_weight_fraction_leaf=0.0, n_estimators=10, n_jobs=1,
1199+
min_weight_fraction_leaf=0.0, n_estimators=100, n_jobs=1,
11981200
oob_score=False, random_state=0, verbose=0, warm_start=False)
11991201
>>> print(regr.feature_importances_)
1200-
[0.17339552 0.81594114 0. 0.01066333]
1202+
[0.18146984 0.81473937 0.00145312 0.00233767]
12011203
>>> print(regr.predict([[0, 0, 0, 0]]))
1202-
[-2.50699856]
1204+
[-8.32987858]
12031205
12041206
Notes
12051207
-----

sklearn/ensemble/tests/test_bagging.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
# Author: Gilles Louppe
66
# License: BSD 3 clause
77

8+
import pytest
89
import numpy as np
910

1011
from sklearn.base import BaseEstimator
@@ -496,6 +497,7 @@ def test_parallel_regression():
496497
assert_array_almost_equal(y1, y3)
497498

498499

500+
@pytest.mark.filterwarnings('ignore: The default of the `iid`') # 0.22
499501
def test_gridsearch():
500502
# Check that bagging ensembles can be grid-searched.
501503
# Transform iris into a binary classification task

sklearn/ensemble/tests/test_forest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,13 +439,13 @@ def check_oob_score_raise_error(name):
439439
def test_oob_score_raise_error(name):
440440
check_oob_score_raise_error(name)
441441

442-
443442
def check_gridsearch(name):
444443
forest = FOREST_CLASSIFIERS[name]()
445444
clf = GridSearchCV(forest, {'n_estimators': (1, 2), 'max_depth': (1, 2)})
446445
clf.fit(iris.data, iris.target)
447446

448447

448+
@pytest.mark.filterwarnings('ignore: The default of the `iid`') # 0.22
449449
@pytest.mark.parametrize('name', FOREST_CLASSIFIERS)
450450
def test_gridsearch(name):
451451
# Check that base trees can be grid-searched.

sklearn/ensemble/tests/test_partial_dependence.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""
22
Testing for the partial dependence module.
33
"""
4+
import pytest
45

56
import numpy as np
67
from numpy.testing import assert_array_equal
@@ -103,6 +104,8 @@ def test_partial_dependecy_input():
103104
assert_raises(ValueError, partial_dependence, clf, [0], grid=grid)
104105

105106

107+
@pytest.mark.filterwarnings('ignore: Using or importing the ABCs from')
108+
# matplotlib Python3.7 warning
106109
@if_matplotlib
107110
def test_plot_partial_dependence():
108111
# Test partial dependence plot function.
@@ -135,6 +138,8 @@ def test_plot_partial_dependence():
135138
assert all(ax.has_data for ax in axs)
136139

137140

141+
@pytest.mark.filterwarnings('ignore: Using or importing the ABCs from')
142+
# matplotlib Python3.7 warning
138143
@if_matplotlib
139144
def test_plot_partial_dependence_input():
140145
# Test partial dependence plot function input checks.
@@ -170,6 +175,8 @@ def test_plot_partial_dependence_input():
170175
clf, X, [{'foo': 'bar'}])
171176

172177

178+
@pytest.mark.filterwarnings('ignore: Using or importing the ABCs from')
179+
# matplotlib Python3.7 warning
173180
@if_matplotlib
174181
def test_plot_partial_dependence_multiclass():
175182
# Test partial dependence plot function on multi-class input.

sklearn/ensemble/tests/test_voting_classifier.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -371,10 +371,12 @@ def test_set_estimator_none():
371371
X1 = np.array([[1], [2]])
372372
y1 = np.array([1, 2])
373373
eclf1 = VotingClassifier(estimators=[('rf', clf2), ('nb', clf3)],
374-
voting='soft', weights=[0, 0.5]).fit(X1, y1)
374+
voting='soft', weights=[0, 0.5],
375+
flatten_transform=False).fit(X1, y1)
375376

376377
eclf2 = VotingClassifier(estimators=[('rf', clf2), ('nb', clf3)],
377-
voting='soft', weights=[1, 0.5])
378+
voting='soft', weights=[1, 0.5],
379+
flatten_transform=False)
378380
eclf2.set_params(rf=None).fit(X1, y1)
379381
assert_array_almost_equal(eclf1.transform(X1),
380382
np.array([[[0.7, 0.3], [0.3, 0.7]],

0 commit comments

Comments
 (0)
0