Skip to content

Commit 14dd5ab

Browse files
committed
Update warnings (#1346)
* Added ignored_warnings file * Use ignored_warnings file * Test regressors with 1d, 1d as 2d and 2d targets * Flake'd * Fix broken relative imports to ignore_warnings * Removed print and updated parameter type for tests * Added warning catches to fit methods in tests * Added more warning catches * Flake'd * Created top-level module to allow relativei imports * Deleted blank line in __init__ * Remove uneeded ignore warnings from tests * Fix bad indent * Fix github merge conflict editor whitespaces and indents
1 parent 45a7df5 commit 14dd5ab

File tree

5 files changed

+65
-19
lines changed

5 files changed

+65
-19
lines changed

test/test_pipeline/components/classification/test_base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import sklearn.metrics
1010
import numpy as np
1111

12-
from test.test_pipeline.ignored_warnings import ignore_warnings, classifier_warnings
12+
from ...ignored_warnings import ignore_warnings, classifier_warnings
1313

1414

1515
class BaseClassificationComponentTest(unittest.TestCase):

test/test_pipeline/components/feature_preprocessing/test_liblinear.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
get_dataset
66
import sklearn.metrics
77

8-
from test.test_pipeline.ignored_warnings import ignore_warnings, feature_preprocessing_warnings
8+
from ...ignored_warnings import ignore_warnings, feature_preprocessing_warnings
99

1010

1111
class LiblinearComponentTest(PreprocessingTestCase):

test/test_pipeline/components/regression/test_base.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ def test_default_boston(self):
3535

3636
for _ in range(2):
3737

38+
with ignore_warnings(regressor_warnings):
39+
predictions, targets, n_calls = _test_regressor(
40+
dataset="boston",
41+
Regressor=self.module
42+
)
43+
3844
with ignore_warnings(regressor_warnings):
3945
predictions, targets, n_calls = _test_regressor(
4046
dataset="boston",
@@ -331,7 +337,7 @@ def test_fit_and_predict_with_1d_targets_as_1d(
331337
regressor: Type[RegressorChoice],
332338
X: np.ndarray,
333339
y: np.ndarray
334-
):
340+
) -> None:
335341
"""Test that all pipelines work with 1d target types
336342
337343
Parameters
@@ -374,7 +380,7 @@ def test_fit_and_predict_with_1d_targets_as_2d(
374380
regressor: Type[RegressorChoice],
375381
X: np.ndarray,
376382
y: np.ndarray
377-
):
383+
) -> None:
378384
"""Test that all pipelines work with 1d target types when they are wrapped as 2d
379385
380386
Parameters
@@ -423,7 +429,7 @@ def test_fit_and_predict_with_2d_targets(
423429
regressor: Type[RegressorChoice],
424430
X: np.ndarray,
425431
y: np.ndarray
426-
):
432+
) -> None:
427433
"""Test that all pipelines work with 2d target types
428434
429435
Parameters

test/test_pipeline/ignored_warnings.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from typing import List, Iterator, Tuple
33

44
import warnings
5+
56
from sklearn.exceptions import ConvergenceWarning
67

78

@@ -68,14 +69,34 @@
6869
r" optimization hasn't converged yet\."
6970
)
7071
),
72+
(
73+
ConvergenceWarning, ( # From FastICA
74+
r"FastICA did not converge\."
75+
r" Consider increasing tolerance or the maximum number of iterations\."
76+
)
77+
),
7178
(
7279
UserWarning, ( # From LDA (Linear Discriminant Analysis)
7380
r"Variables are collinear"
7481
)
7582
),
83+
(
84+
UserWarning, (
85+
r"Clustering metrics expects discrete values but received continuous values"
86+
r" for label, and multiclass values for target"
87+
)
88+
)
89+
]
90+
91+
feature_preprocessing_warnings = [
92+
(
93+
ConvergenceWarning, ( # From liblinear
94+
r"Liblinear failed to converge, increase the number of iterations."
95+
)
96+
)
7697
]
7798

78-
ignored_warnings = regressor_warnings + classifier_warnings
99+
ignored_warnings = regressor_warnings + classifier_warnings + feature_preprocessing_warnings
79100

80101

81102
@contextmanager

test/test_pipeline/test_classification.py

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,9 @@ def test_default_configuration(self):
173173

174174
auto = SimpleClassificationPipeline(random_state=1)
175175

176-
auto = auto.fit(X_train, Y_train)
176+
with ignore_warnings(classifier_warnings):
177+
auto = auto.fit(X_train, Y_train)
178+
177179
predictions = auto.predict(X_test)
178180

179181
acc = sklearn.metrics.accuracy_score(predictions, Y_test)
@@ -196,7 +198,9 @@ def test_default_configuration_multilabel(self):
196198
default = cs.get_default_configuration()
197199
classifier.set_hyperparameters(default)
198200

199-
classifier = classifier.fit(X_train, Y_train)
201+
with ignore_warnings(classifier_warnings):
202+
classifier = classifier.fit(X_train, Y_train)
203+
200204
predictions = classifier.predict(X_test)
201205

202206
acc = sklearn.metrics.accuracy_score(predictions, Y_test)
@@ -221,10 +225,12 @@ def test_default_configuration_iterative_fit(self):
221225
random_state=0
222226
)
223227
classifier.fit_transformer(X_train, Y_train)
224-
for i in range(1, 11):
225-
classifier.iterative_fit(X_train, Y_train)
226-
n_estimators = classifier.steps[-1][-1].choice.estimator.n_estimators
227-
self.assertEqual(n_estimators, i)
228+
229+
with ignore_warnings(classifier_warnings):
230+
for i in range(1, 11):
231+
classifier.iterative_fit(X_train, Y_train)
232+
n_estimators = classifier.steps[-1][-1].choice.estimator.n_estimators
233+
self.assertEqual(n_estimators, i)
228234

229235
def test_repr(self):
230236
"""Test that the default pipeline can be converted to its representation and
@@ -727,7 +733,9 @@ def test_predict_batched(self):
727733

728734
# Multiclass
729735
X_train, Y_train, X_test, Y_test = get_dataset(dataset='digits')
730-
cls.fit(X_train, Y_train)
736+
737+
with ignore_warnings(classifier_warnings):
738+
cls.fit(X_train, Y_train)
731739

732740
X_test_ = X_test.copy()
733741
prediction_ = cls.predict_proba(X_test_)
@@ -759,7 +767,8 @@ def test_predict_batched_sparse(self):
759767

760768
# Multiclass
761769
X_train, Y_train, X_test, Y_test = get_dataset(dataset='digits', make_sparse=True)
762-
cls.fit(X_train, Y_train)
770+
with ignore_warnings(classifier_warnings):
771+
cls.fit(X_train, Y_train)
763772

764773
X_test_ = X_test.copy()
765774
prediction_ = cls.predict_proba(X_test_)
@@ -788,7 +797,8 @@ def test_predict_proba_batched(self):
788797
cls = SimpleClassificationPipeline(include={'classifier': ['sgd']})
789798
X_train, Y_train, X_test, Y_test = get_dataset(dataset='digits')
790799

791-
cls.fit(X_train, Y_train)
800+
with ignore_warnings(classifier_warnings):
801+
cls.fit(X_train, Y_train)
792802

793803
X_test_ = X_test.copy()
794804
prediction_ = cls.predict_proba(X_test_)
@@ -808,7 +818,9 @@ def test_predict_proba_batched(self):
808818
X_train, Y_train, X_test, Y_test = get_dataset(dataset='digits')
809819
Y_train = np.array(list([(list([1 if i != y else 0 for i in range(10)]))
810820
for y in Y_train]))
811-
cls.fit(X_train, Y_train)
821+
822+
with ignore_warnings(classifier_warnings):
823+
cls.fit(X_train, Y_train)
812824

813825
X_test_ = X_test.copy()
814826
prediction_ = cls.predict_proba(X_test_)
@@ -842,7 +854,9 @@ def test_predict_proba_batched_sparse(self):
842854
X_train, Y_train, X_test, Y_test = get_dataset(dataset='digits', make_sparse=True)
843855
X_test_ = X_test.copy()
844856

845-
cls.fit(X_train, Y_train)
857+
with ignore_warnings(classifier_warnings):
858+
cls.fit(X_train, Y_train)
859+
846860
prediction_ = cls.predict_proba(X_test_)
847861

848862
# The object behind the last step in the pipeline
@@ -861,10 +875,13 @@ def test_predict_proba_batched_sparse(self):
861875
include={'classifier': ['lda']}
862876
)
863877
X_train, Y_train, X_test, Y_test = get_dataset(dataset='digits', make_sparse=True)
878+
864879
X_test_ = X_test.copy()
865880
Y_train = np.array([[1 if i != y else 0 for i in range(10)] for y in Y_train])
866881

867-
cls.fit(X_train, Y_train)
882+
with ignore_warnings(classifier_warnings):
883+
cls.fit(X_train, Y_train)
884+
868885
prediction_ = cls.predict_proba(X_test_)
869886

870887
# The object behind the last step in the pipeline
@@ -889,7 +906,9 @@ def test_pipeline_clonability(self):
889906
X_train, Y_train, X_test, Y_test = get_dataset(dataset='iris')
890907

891908
auto = SimpleClassificationPipeline()
892-
auto = auto.fit(X_train, Y_train)
909+
910+
with ignore_warnings(classifier_warnings):
911+
auto = auto.fit(X_train, Y_train)
893912

894913
auto_clone = clone(auto)
895914
auto_clone_params = auto_clone.get_params()

0 commit comments

Comments
 (0)