Skip to content

Commit 43cf470

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 766fd3f commit 43cf470

File tree

8 files changed

+174
-76
lines changed

8 files changed

+174
-76
lines changed

test/__init__.py

Whitespace-only changes.

test/test_automl/test_automl.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,9 @@ def test_fit(dask_client):
6464
metric=accuracy,
6565
dask_client=dask_client,
6666
)
67-
automl.fit(
68-
X_train, Y_train, task=MULTICLASS_CLASSIFICATION
69-
)
67+
68+
automl.fit(X_train, Y_train, task=MULTICLASS_CLASSIFICATION)
69+
7070
score = automl.score(X_test, Y_test)
7171
assert score > 0.8
7272
assert count_succeses(automl.cv_results_) > 0
@@ -109,9 +109,9 @@ def get_roar_object_callback(
109109
metric=accuracy,
110110
dask_client=dask_client_single_worker,
111111
)
112-
automl.fit(
113-
X_train, Y_train, task=MULTICLASS_CLASSIFICATION,
114-
)
112+
113+
automl.fit(X_train, Y_train, task=MULTICLASS_CLASSIFICATION)
114+
115115
score = automl.score(X_test, Y_test)
116116
assert score > 0.8
117117
assert count_succeses(automl.cv_results_) > 0
@@ -224,8 +224,7 @@ def test_delete_non_candidate_models(dask_client):
224224
max_models_on_disc=3,
225225
)
226226

227-
automl.fit(X, Y, task=MULTICLASS_CLASSIFICATION,
228-
X_test=X, y_test=Y)
227+
automl.fit(X, Y, task=MULTICLASS_CLASSIFICATION, X_test=X, y_test=Y)
229228

230229
# Assert at least one model file has been deleted and that there were no
231230
# deletion errors
@@ -271,7 +270,9 @@ def test_binary_score_and_include(dask_client):
271270
metric=accuracy,
272271
dask_client=dask_client,
273272
)
273+
274274
automl.fit(X_train, Y_train, task=BINARY_CLASSIFICATION)
275+
275276
assert automl._task == BINARY_CLASSIFICATION
276277

277278
# TODO, the assumption from above is not really tested here
@@ -294,6 +295,7 @@ def test_automl_outputs(dask_client):
294295
dask_client=dask_client,
295296
delete_tmp_folder_after_terminate=False,
296297
)
298+
297299
auto.fit(
298300
X=X_train,
299301
y=Y_train,
@@ -302,6 +304,7 @@ def test_automl_outputs(dask_client):
302304
dataset_name=name,
303305
task=MULTICLASS_CLASSIFICATION,
304306
)
307+
305308
data_manager_file = os.path.join(
306309
auto._backend.temporary_directory,
307310
'.auto-sklearn',
@@ -624,9 +627,8 @@ def test_load_best_individual_model(metric, dask_client):
624627
# We cannot easily mock a function sent to dask
625628
# so for this test we create the whole set of models/ensembles
626629
# but prevent it to be loaded
627-
automl.fit(
628-
X_train, Y_train, task=MULTICLASS_CLASSIFICATION,
629-
)
630+
automl.fit(X_train, Y_train, task=MULTICLASS_CLASSIFICATION)
631+
630632
automl._backend.load_ensemble = unittest.mock.MagicMock(return_value=None)
631633

632634
# A memory error occurs in the ensemble construction

test/test_automl/test_estimators.py

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ def __call__(self, *args, **kwargs):
7979
get_smac_object_callback=get_smac_object_wrapper_instance,
8080
max_models_on_disc=None,
8181
)
82+
8283
automl.fit(X_train, Y_train)
8384

8485
# Test that the argument is correctly passed to SMAC
@@ -272,6 +273,7 @@ def test_performance_over_time_no_ensemble(tmp_dir):
272273
seed=1,
273274
initial_configurations_via_metalearning=0,
274275
ensemble_size=0,)
276+
275277
cls.fit(X_train, Y_train, X_test, Y_test)
276278

277279
performance_over_time = cls.performance_over_time_
@@ -297,6 +299,7 @@ def test_cv_results(tmp_dir):
297299
original_params = copy.deepcopy(params)
298300

299301
cls.fit(X_train, Y_train)
302+
300303
cv_results = cls.cv_results_
301304
assert isinstance(cv_results, dict), type(cv_results)
302305
assert isinstance(cv_results['mean_test_score'], np.ndarray), type(
@@ -382,6 +385,7 @@ def test_leaderboard(
382385
tmp_folder=tmp_dir,
383386
seed=1
384387
)
388+
385389
model.fit(X_train, Y_train)
386390

387391
for params in params_generator:
@@ -540,6 +544,7 @@ def test_can_pickle_classifier(tmp_dir, dask_client):
540544
tmp_folder=tmp_dir,
541545
dask_client=dask_client,
542546
)
547+
543548
automl.fit(X_train, Y_train)
544549

545550
initial_predictions = automl.predict(X_test)
@@ -765,12 +770,14 @@ def test_autosklearn_classification_methods_returns_self(dask_client):
765770
exclude={'feature_preprocessor': ['fast_ica']})
766771

767772
automl_fitted = automl.fit(X_train, y_train)
773+
768774
assert automl is automl_fitted
769775

770776
automl_ensemble_fitted = automl.fit_ensemble(y_train, ensemble_size=5)
771777
assert automl is automl_ensemble_fitted
772778

773779
automl_refitted = automl.refit(X_train.copy(), y_train.copy())
780+
774781
assert automl is automl_refitted
775782

776783

@@ -801,12 +808,14 @@ def test_autosklearn2_classification_methods_returns_self(dask_client):
801808
dask_client=dask_client)
802809

803810
automl_fitted = automl.fit(X_train, y_train)
811+
804812
assert automl is automl_fitted
805813

806814
automl_ensemble_fitted = automl.fit_ensemble(y_train, ensemble_size=5)
807815
assert automl is automl_ensemble_fitted
808816

809817
automl_refitted = automl.refit(X_train.copy(), y_train.copy())
818+
810819
assert automl is automl_refitted
811820

812821
predictions = automl_fitted.predict(X_test)
@@ -824,12 +833,14 @@ def test_autosklearn2_classification_methods_returns_self_sparse(dask_client):
824833
dask_client=dask_client)
825834

826835
automl_fitted = automl.fit(X_train, y_train)
836+
827837
assert automl is automl_fitted
828838

829839
automl_ensemble_fitted = automl.fit_ensemble(y_train, ensemble_size=5)
830840
assert automl is automl_ensemble_fitted
831841

832842
automl_refitted = automl.refit(X_train.copy(), y_train.copy())
843+
833844
assert automl is automl_refitted
834845

835846
predictions = automl_fitted.predict(X_test)
@@ -933,10 +944,15 @@ def test_fit_pipeline(dask_client, task_type, resampling_strategy, disable_file_
933944
X_test=X_test, y_test=y_test,
934945
).get_default_configuration()
935946

936-
pipeline, run_info, run_value = automl.fit_pipeline(X=X_train, y=y_train, config=config,
937-
X_test=X_test, y_test=y_test,
938-
disable_file_output=disable_file_output,
939-
resampling_strategy=resampling_strategy)
947+
pipeline, run_info, run_value = automl.fit_pipeline(
948+
X=X_train,
949+
y=y_train,
950+
config=config,
951+
X_test=X_test,
952+
y_test=y_test,
953+
disable_file_output=disable_file_output,
954+
resampling_strategy=resampling_strategy
955+
)
940956

941957
assert isinstance(run_info.config, Configuration)
942958
assert run_info.cutoff == 30
@@ -1090,11 +1106,14 @@ def test_autosklearn_anneal(as_frame):
10901106
if as_frame:
10911107
# Let autosklearn calculate the feat types
10921108
automl_fitted = automl.fit(X, y)
1109+
10931110
else:
10941111
X_, y_ = sklearn.datasets.fetch_openml(data_id=2, return_X_y=True, as_frame=True)
10951112
feat_type = ['categorical' if X_[col].dtype.name == 'category' else 'numerical'
10961113
for col in X_.columns]
1114+
10971115
automl_fitted = automl.fit(X, y, feat_type=feat_type)
1116+
10981117
assert automl is automl_fitted
10991118

11001119
automl_ensemble_fitted = automl.fit_ensemble(y, ensemble_size=5)

test/test_pipeline/components/classification/test_base.py

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

12+
from ...ignored_warnings import ignore_warnings, classifier_warnings
13+
1214

1315
class BaseClassificationComponentTest(unittest.TestCase):
1416
# Magic command to not run tests on base class
@@ -274,7 +276,8 @@ def is_unset_param_raw_predictions_val_error(err):
274276
+ " assignment" in err.args[0])
275277

276278
try:
277-
model.fit(X.copy(), y.copy())
279+
with ignore_warnings(classifier_warnings):
280+
model.fit(X.copy(), y.copy())
278281
except ValueError as e:
279282
if is_AdaBoostClassifier_error(e) or is_QDA_error(e):
280283
return None

test/test_pipeline/components/feature_preprocessing/test_liblinear.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,15 @@
55
get_dataset
66
import sklearn.metrics
77

8+
from ...ignored_warnings import ignore_warnings, feature_preprocessing_warnings
9+
810

911
class LiblinearComponentTest(PreprocessingTestCase):
12+
1013
def test_default_configuration(self):
11-
transformation, original = _test_preprocessing(LibLinear_Preprocessor)
14+
with ignore_warnings(feature_preprocessing_warnings):
15+
transformation, original = _test_preprocessing(LibLinear_Preprocessor)
16+
1217
self.assertEqual(transformation.shape[0], original.shape[0])
1318
self.assertFalse((transformation == 0).all())
1419

@@ -23,7 +28,10 @@ def test_default_configuration_classify(self):
2328
for hp_name in
2429
default if default[
2530
hp_name] is not None})
26-
preprocessor.fit(X_train, Y_train)
31+
32+
with ignore_warnings(feature_preprocessing_warnings):
33+
preprocessor.fit(X_train, Y_train)
34+
2735
X_train_trans = preprocessor.transform(X_train)
2836
X_test_trans = preprocessor.transform(X_test)
2937

@@ -35,6 +43,6 @@ def test_default_configuration_classify(self):
3543
self.assertAlmostEqual(accuracy, 0.8548876745598057, places=2)
3644

3745
def test_preprocessing_dtype(self):
38-
super(LiblinearComponentTest,
39-
self)._test_preprocessing_dtype(LibLinear_Preprocessor,
40-
test_sparse=False)
46+
47+
with ignore_warnings(feature_preprocessing_warnings):
48+
super()._test_preprocessing_dtype(LibLinear_Preprocessor, test_sparse=False)

0 commit comments

Comments
 (0)