diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index cd5922ab2..116a70261 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,14 +1,17 @@ repos: - repo: https://github.com/psf/black - rev: stable + rev: 22.3.0 hooks: - id: black language_version: python3 + - repo: https://github.com/pycqa/flake8 + rev: 4.0.1 + hooks: + - id: flake8 - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v1.2.3 + rev: v4.3.0 hooks: - - id: flake8 - id: check-added-large-files - id: check-ast - id: check-byte-order-marker diff --git a/test/automl/test_constraints.py b/test/automl/test_constraints.py index a47be3078..7555100d3 100644 --- a/test/automl/test_constraints.py +++ b/test/automl/test_constraints.py @@ -1,11 +1,11 @@ -import unittest - +from urllib.error import URLError from sklearn.datasets import fetch_openml from sklearn.model_selection import train_test_split -from flaml.automl import AutoML +from sklearn.externals._arff import ArffException +from functools import partial +from flaml.automl import AutoML, size from flaml import tune - dataset = "credit-g" @@ -24,11 +24,10 @@ def test_metric_constraints(): "time_budget": 2, "pred_time_limit": 5.1e-05, } - from sklearn.externals._arff import ArffException try: X, y = fetch_openml(name=dataset, return_X_y=True) - except (ArffException, ValueError): + except (ArffException, ValueError, URLError): from sklearn.datasets import load_wine X, y = load_wine(return_X_y=True) @@ -42,10 +41,6 @@ def test_metric_constraints(): config = automl.best_config.copy() config["learner"] = automl.best_estimator automl.trainable(config) - - from flaml.automl import size - from functools import partial - print("metric constraints used in automl", automl.metric_constraints) analysis = tune.run( @@ -117,7 +112,6 @@ def test_metric_constraints_custom(): ("val_train_loss_gap", "<=", 0.05), ], } - from sklearn.externals._arff import ArffException try: X, y = fetch_openml(name=dataset, return_X_y=True) @@ -151,11 +145,8 @@ def test_metric_constraints_custom(): config = automl.best_config.copy() config["learner"] = automl.best_estimator automl.trainable(config) - - from flaml.automl import size - from functools import partial - print("metric constraints in automl", automl.metric_constraints) + analysis = tune.run( automl.trainable, automl.search_space, @@ -176,4 +167,5 @@ def test_metric_constraints_custom(): if __name__ == "__main__": - unittest.main() + test_metric_constraints() + test_metric_constraints_custom()