diff --git a/benchmarks/bench_plot_fastkmeans.py b/benchmarks/bench_plot_fastkmeans.py index dd37f159a5c91..9abceaa67a938 100644 --- a/benchmarks/bench_plot_fastkmeans.py +++ b/benchmarks/bench_plot_fastkmeans.py @@ -90,7 +90,7 @@ def compute_bench_2(chunks): if __name__ == '__main__': - from mpl_toolkits.mplot3d import axes3d # register the 3d projection + from mpl_toolkits.mplot3d import axes3d # noqa register the 3d projection import matplotlib.pyplot as plt samples_range = np.linspace(50, 150, 5).astype(int) diff --git a/benchmarks/bench_plot_lasso_path.py b/benchmarks/bench_plot_lasso_path.py index a1530bb5c06c4..0952969f88844 100644 --- a/benchmarks/bench_plot_lasso_path.py +++ b/benchmarks/bench_plot_lasso_path.py @@ -32,7 +32,7 @@ def compute_bench(samples_range, features_range): 'n_features': n_features, 'n_informative': n_features // 10, 'effective_rank': min(n_samples, n_features) / 10, - #'effective_rank': None, + # 'effective_rank': None, 'bias': 0.0, } print("n_samples: %d" % n_samples) @@ -81,7 +81,7 @@ def compute_bench(samples_range, features_range): if __name__ == '__main__': - from mpl_toolkits.mplot3d import axes3d # register the 3d projection + from mpl_toolkits.mplot3d import axes3d # noqa register the 3d projection import matplotlib.pyplot as plt samples_range = np.linspace(10, 2000, 5).astype(int) diff --git a/benchmarks/bench_plot_randomized_svd.py b/benchmarks/bench_plot_randomized_svd.py index f752eeb5e863b..cc372070fe378 100644 --- a/benchmarks/bench_plot_randomized_svd.py +++ b/benchmarks/bench_plot_randomized_svd.py @@ -239,7 +239,7 @@ def svd_timing(X, n_comps, n_iter, n_oversamples, Measure time for decomposition """ print("... running SVD ...") - if method is not 'fbpca': + if method != 'fbpca': gc.collect() t0 = time() U, mu, V = randomized_svd(X, n_comps, n_oversamples, n_iter, diff --git a/benchmarks/bench_plot_svd.py b/benchmarks/bench_plot_svd.py index e58fb48c3051c..877fd4c125cb9 100644 --- a/benchmarks/bench_plot_svd.py +++ b/benchmarks/bench_plot_svd.py @@ -54,7 +54,7 @@ def compute_bench(samples_range, features_range, n_iter=3, rank=50): if __name__ == '__main__': - from mpl_toolkits.mplot3d import axes3d # register the 3d projection + from mpl_toolkits.mplot3d import axes3d # noqa register the 3d projection import matplotlib.pyplot as plt samples_range = np.linspace(2, 1000, 4).astype(int) diff --git a/benchmarks/bench_rcv1_logreg_convergence.py b/benchmarks/bench_rcv1_logreg_convergence.py index 051496c4483a2..eb8e6096756ec 100644 --- a/benchmarks/bench_rcv1_logreg_convergence.py +++ b/benchmarks/bench_rcv1_logreg_convergence.py @@ -39,7 +39,7 @@ def bench_one(name, clf_type, clf_params, n_iter): clf = clf_type(**clf_params) try: clf.set_params(max_iter=n_iter, random_state=42) - except: + except Exception: clf.set_params(n_iter=n_iter, random_state=42) st = time.time() @@ -48,12 +48,12 @@ def bench_one(name, clf_type, clf_params, n_iter): try: C = 1.0 / clf.alpha / n_samples - except: + except Exception: C = clf.C try: intercept = clf.intercept_ - except: + except Exception: intercept = 0. train_loss = get_loss(clf.coef_, intercept, X, y, C) diff --git a/pyproject.toml b/pyproject.toml index d172baaea7088..30d2e124e2c9f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -16,3 +16,28 @@ requires = [ "scipy>=1.1.0", ] + +[tool.black] +line-length = 88 +exclude = ''' + +( + /( + \.eggs # exclude a few common directories in the + | \.git # root of the project + | \.mypy_cache + | examples + | build + | dist + | doc + | sklearn/externals + )/ +) +''' +include = ''' +( + /( + doc/conf.py + )/ +) +''' diff --git a/setup.cfg b/setup.cfg index 1296273f721c4..fe4139d8d0067 100644 --- a/setup.cfg +++ b/setup.cfg @@ -26,8 +26,31 @@ artifact_indexes= https://pypi.anaconda.org/scikit-learn-wheels-staging/simple/scikit-learn/ [flake8] +# max line length for black +max-line-length = 88 +target-version = ['py37'] # Default flake8 3.5 ignored flags -ignore=E121,E123,E126,E226,E24,E704,W503,W504 +ignore= + E24, # check ignored by default in flake8. Meaning unclear. + E121, # continuation line under-indented + E123, # closing bracket does not match indentation + E126, # continuation line over-indented for hanging indent + E203, # space before : (needed for how black formats slicing) + E226, # missing whitespace around arithmetic operator + E704, # multiple statements on one line (def) + E731, # do not assign a lambda expression, use a def + E741, # do not use variables named ‘l’, ‘O’, or ‘I’ + W503, # line break before binary operator + W504 # line break after binary operator +exclude= + .git, + __pycache__, + dist, + sklearn/externals, + doc/_build, + doc/auto_examples, + doc/tutorial + # It's fine not to put the import at the top of the file in the examples # folder. per-file-ignores = diff --git a/setup.py b/setup.py index 91602bafca408..221c7eefb213c 100755 --- a/setup.py +++ b/setup.py @@ -48,7 +48,7 @@ # We can actually import a restricted version of sklearn that # does not need the compiled code -import sklearn +import sklearn # noqa import sklearn._min_dependencies as min_deps # noqa from sklearn.externals._packaging.version import parse as parse_version # noqa diff --git a/sklearn/calibration.py b/sklearn/calibration.py index abdbed1bb797b..c5b8a959c0135 100644 --- a/sklearn/calibration.py +++ b/sklearn/calibration.py @@ -382,7 +382,7 @@ def _more_tags(self): return { '_xfail_checks': { 'check_sample_weights_invariance': - 'zero sample_weight is not equivalent to removing samples', + ('zero sample_weight is not equivalent to removing samples'), } } diff --git a/sklearn/cluster/_affinity_propagation.py b/sklearn/cluster/_affinity_propagation.py index cf0da5c5bc0f3..63b526054f7f9 100644 --- a/sklearn/cluster/_affinity_propagation.py +++ b/sklearn/cluster/_affinity_propagation.py @@ -371,8 +371,9 @@ def __init__(self, *, damping=.5, max_iter=200, convergence_iter=15, # TODO: Remove in 1.1 # mypy error: Decorated property not supported - @deprecated("Attribute _pairwise was deprecated in " # type: ignore - "version 0.24 and will be removed in 1.1 (renaming of 0.26).") + @deprecated( # type: ignore + "Attribute _pairwise was deprecated in " + "version 0.24 and will be removed in 1.1 (renaming of 0.26).") @property def _pairwise(self): return self.affinity == "precomputed" diff --git a/sklearn/cluster/_kmeans.py b/sklearn/cluster/_kmeans.py index 6b54ec99ae825..a615aba9c3559 100644 --- a/sklearn/cluster/_kmeans.py +++ b/sklearn/cluster/_kmeans.py @@ -1227,7 +1227,7 @@ def _more_tags(self): return { '_xfail_checks': { 'check_sample_weights_invariance': - 'zero sample_weight is not equivalent to removing samples', + ('zero sample_weight is not equivalent to removing samples'), }, } @@ -1530,20 +1530,23 @@ def __init__(self, n_clusters=8, *, init='k-means++', max_iter=100, self.init_size = init_size self.reassignment_ratio = reassignment_ratio - @deprecated("The attribute 'counts_' is deprecated in 0.24" # type: ignore - " and will be removed in 1.1 (renaming of 0.26).") + @deprecated( # type: ignore + "The attribute 'counts_' is deprecated in 0.24" + " and will be removed in 1.1 (renaming of 0.26).") @property def counts_(self): return self._counts - @deprecated("The attribute 'init_size_' is deprecated in " # type: ignore - "0.24 and will be removed in 1.1 (renaming of 0.26).") + @deprecated( # type: ignore + "The attribute 'init_size_' is deprecated in " + "0.24 and will be removed in 1.1 (renaming of 0.26).") @property def init_size_(self): return self._init_size - @deprecated("The attribute 'random_state_' is deprecated " # type: ignore - "in 0.24 and will be removed in 1.1 (renaming of 0.26).") + @deprecated( # type: ignore + "The attribute 'random_state_' is deprecated " + "in 0.24 and will be removed in 1.1 (renaming of 0.26).") @property def random_state_(self): return getattr(self, "_random_state", None) @@ -1923,6 +1926,6 @@ def _more_tags(self): return { '_xfail_checks': { 'check_sample_weights_invariance': - 'zero sample_weight is not equivalent to removing samples', + ('zero sample_weight is not equivalent to removing samples'), } } diff --git a/sklearn/cluster/_spectral.py b/sklearn/cluster/_spectral.py index 8cdbd859fde02..54db6b9a16c95 100644 --- a/sklearn/cluster/_spectral.py +++ b/sklearn/cluster/_spectral.py @@ -592,8 +592,9 @@ def _more_tags(self): # TODO: Remove in 1.1 # mypy error: Decorated property not supported - @deprecated("Attribute _pairwise was deprecated in " # type: ignore - "version 0.24 and will be removed in 1.1 (renaming of 0.26).") + @deprecated( # type: ignore + "Attribute _pairwise was deprecated in " + "version 0.24 and will be removed in 1.1 (renaming of 0.26).") @property def _pairwise(self): return self.affinity in ["precomputed", diff --git a/sklearn/decomposition/_dict_learning.py b/sklearn/decomposition/_dict_learning.py index e8d2241241799..d346ddbae653e 100644 --- a/sklearn/decomposition/_dict_learning.py +++ b/sklearn/decomposition/_dict_learning.py @@ -1101,9 +1101,10 @@ def fit(self, X, y=None): """ return self - @deprecated("The attribute 'components_' is deprecated " # type: ignore - "in 0.24 and will be removed in 1.1 (renaming of 0.26). Use " - "the 'dictionary' instead.") + @deprecated( # type: ignore + "The attribute 'components_' is deprecated " + "in 0.24 and will be removed in 1.1 (renaming of 0.26). Use the " + "'dictionary' instead.") @property def components_(self): return self.dictionary diff --git a/sklearn/decomposition/_kernel_pca.py b/sklearn/decomposition/_kernel_pca.py index 70a12f5cb2e38..f6b9f68a138ae 100644 --- a/sklearn/decomposition/_kernel_pca.py +++ b/sklearn/decomposition/_kernel_pca.py @@ -224,8 +224,9 @@ def __init__(self, n_components=None, *, kernel="linear", # TODO: Remove in 1.1 # mypy error: Decorated property not supported - @deprecated("Attribute _pairwise was deprecated in " # type: ignore - "version 0.24 and will be removed in 1.1 (renaming of 0.26).") + @deprecated( # type: ignore + "Attribute _pairwise was deprecated in " + "version 0.24 and will be removed in 1.1 (renaming of 0.26).") @property def _pairwise(self): return self.kernel == "precomputed" diff --git a/sklearn/ensemble/_gb.py b/sklearn/ensemble/_gb.py index 496757ee9d605..db7a1533eba3f 100644 --- a/sklearn/ensemble/_gb.py +++ b/sklearn/ensemble/_gb.py @@ -1766,9 +1766,9 @@ def apply(self, X): # FIXME: to be removed in 1.1 # mypy error: Decorated property not supported - @deprecated("Attribute n_classes_ was deprecated " # type: ignore - "in version 0.24 and will be removed in 1.1 " - "(renaming of 0.26).") + @deprecated( # type: ignore + "Attribute n_classes_ was deprecated " + "in version 0.24 and will be removed in 1.1 (renaming of 0.26).") @property def n_classes_(self): try: diff --git a/sklearn/ensemble/_iforest.py b/sklearn/ensemble/_iforest.py index fb8614ae0528e..7f68c46ecfc2e 100644 --- a/sklearn/ensemble/_iforest.py +++ b/sklearn/ensemble/_iforest.py @@ -468,7 +468,7 @@ def _more_tags(self): return { '_xfail_checks': { 'check_sample_weights_invariance': - 'zero sample_weight is not equivalent to removing samples', + ('zero sample_weight is not equivalent to removing samples'), } } diff --git a/sklearn/kernel_approximation.py b/sklearn/kernel_approximation.py index d6d67fe85e941..3ea9318e39c8b 100644 --- a/sklearn/kernel_approximation.py +++ b/sklearn/kernel_approximation.py @@ -854,7 +854,7 @@ def _more_tags(self): return { '_xfail_checks': { 'check_transformer_preserve_dtypes': - 'dtypes are preserved but not at a close enough precision', + ('dtypes are preserved but not at a close enough precision') }, 'preserves_dtype': [np.float64, np.float32] } diff --git a/sklearn/kernel_ridge.py b/sklearn/kernel_ridge.py index 2bb0b83763625..e13f7fd0ad9c7 100644 --- a/sklearn/kernel_ridge.py +++ b/sklearn/kernel_ridge.py @@ -141,8 +141,9 @@ def _more_tags(self): # TODO: Remove in 1.1 # mypy error: Decorated property not supported - @deprecated("Attribute _pairwise was deprecated in " # type: ignore - "version 0.24 and will be removed in 1.1 (renaming of 0.26).") + @deprecated( # type: ignore + "Attribute _pairwise was deprecated in " + "version 0.24 and will be removed in 1.1 (renaming of 0.26).") @property def _pairwise(self): return self.kernel == "precomputed" diff --git a/sklearn/linear_model/_logistic.py b/sklearn/linear_model/_logistic.py index c4876486e16de..0ed10e6753d7e 100644 --- a/sklearn/linear_model/_logistic.py +++ b/sklearn/linear_model/_logistic.py @@ -2140,6 +2140,6 @@ def _more_tags(self): return { '_xfail_checks': { 'check_sample_weights_invariance': - 'zero sample_weight is not equivalent to removing samples', + ('zero sample_weight is not equivalent to removing samples'), } } diff --git a/sklearn/linear_model/_ransac.py b/sklearn/linear_model/_ransac.py index 5ee5b1e2fa502..daa6551084072 100644 --- a/sklearn/linear_model/_ransac.py +++ b/sklearn/linear_model/_ransac.py @@ -531,6 +531,6 @@ def _more_tags(self): return { '_xfail_checks': { 'check_sample_weights_invariance': - 'zero sample_weight is not equivalent to removing samples', + ('zero sample_weight is not equivalent to removing samples'), } } diff --git a/sklearn/linear_model/_ridge.py b/sklearn/linear_model/_ridge.py index d82aca05fee7c..4fa4cb230461f 100644 --- a/sklearn/linear_model/_ridge.py +++ b/sklearn/linear_model/_ridge.py @@ -2004,6 +2004,6 @@ def _more_tags(self): return { '_xfail_checks': { 'check_sample_weights_invariance': - 'zero sample_weight is not equivalent to removing samples', + ('zero sample_weight is not equivalent to removing samples'), } } diff --git a/sklearn/linear_model/_stochastic_gradient.py b/sklearn/linear_model/_stochastic_gradient.py index eb84c06ac93b3..223826c71bc72 100644 --- a/sklearn/linear_model/_stochastic_gradient.py +++ b/sklearn/linear_model/_stochastic_gradient.py @@ -1103,7 +1103,7 @@ def _more_tags(self): return { '_xfail_checks': { 'check_sample_weights_invariance': - 'zero sample_weight is not equivalent to removing samples', + ('zero sample_weight is not equivalent to removing samples'), } } @@ -1590,7 +1590,7 @@ def _more_tags(self): return { '_xfail_checks': { 'check_sample_weights_invariance': - 'zero sample_weight is not equivalent to removing samples', + ('zero sample_weight is not equivalent to removing samples'), } } diff --git a/sklearn/manifold/_mds.py b/sklearn/manifold/_mds.py index f833f24f981a3..9e9018f3c2a31 100644 --- a/sklearn/manifold/_mds.py +++ b/sklearn/manifold/_mds.py @@ -393,8 +393,9 @@ def _more_tags(self): # TODO: Remove in 1.1 # mypy error: Decorated property not supported - @deprecated("Attribute _pairwise was deprecated in " # type: ignore - "version 0.24 and will be removed in 1.1 (renaming of 0.26).") + @deprecated( # type: ignore + "Attribute _pairwise was deprecated in " + "version 0.24 and will be removed in 1.1 (renaming of 0.26).") @property def _pairwise(self): return self.dissimilarity == "precomputed" diff --git a/sklearn/manifold/_spectral_embedding.py b/sklearn/manifold/_spectral_embedding.py index 01bdf06b92ed0..8d9590c0e91b6 100644 --- a/sklearn/manifold/_spectral_embedding.py +++ b/sklearn/manifold/_spectral_embedding.py @@ -492,8 +492,9 @@ def _more_tags(self): # TODO: Remove in 1.1 # mypy error: Decorated property not supported - @deprecated("Attribute _pairwise was deprecated in " # type: ignore - "version 0.24 and will be removed in 1.1 (renaming of 0.26).") + @deprecated( # type: ignore + "Attribute _pairwise was deprecated in " + "version 0.24 and will be removed in 1.1 (renaming of 0.26).") @property def _pairwise(self): return self.affinity in ["precomputed", diff --git a/sklearn/metrics/tests/test_common.py b/sklearn/metrics/tests/test_common.py index 63e37f5590959..f7cdbd39fd944 100644 --- a/sklearn/metrics/tests/test_common.py +++ b/sklearn/metrics/tests/test_common.py @@ -511,14 +511,11 @@ def _require_positive_targets(y1, y2): def test_symmetry_consistency(): # We shouldn't forget any metrics - assert (SYMMETRIC_METRICS.union( - NOT_SYMMETRIC_METRICS, set(THRESHOLDED_METRICS), - METRIC_UNDEFINED_BINARY_MULTICLASS) == - set(ALL_METRICS)) - - assert ( - SYMMETRIC_METRICS.intersection(NOT_SYMMETRIC_METRICS) == - set()) + assert ((SYMMETRIC_METRICS | NOT_SYMMETRIC_METRICS | + set(THRESHOLDED_METRICS) | METRIC_UNDEFINED_BINARY_MULTICLASS) == + set(ALL_METRICS)) + + assert (SYMMETRIC_METRICS & NOT_SYMMETRIC_METRICS) == set() @pytest.mark.parametrize("name", sorted(SYMMETRIC_METRICS)) diff --git a/sklearn/model_selection/_search.py b/sklearn/model_selection/_search.py index 3ee0bcc4ec153..1da6b630349ff 100644 --- a/sklearn/model_selection/_search.py +++ b/sklearn/model_selection/_search.py @@ -367,8 +367,9 @@ def _more_tags(self): # TODO: Remove in 1.1 # mypy error: Decorated property not supported - @deprecated("Attribute _pairwise was deprecated in " # type: ignore - "version 0.24 and will be removed in 1.1 (renaming of 0.26).") + @deprecated( # type: ignore + "Attribute _pairwise was deprecated in " + "version 0.24 and will be removed in 1.1 (renaming of 0.26).") @property def _pairwise(self): # allows cross-validation to see 'precomputed' metrics diff --git a/sklearn/model_selection/_validation.py b/sklearn/model_selection/_validation.py index e473db977bb30..a5dcdbd046173 100644 --- a/sklearn/model_selection/_validation.py +++ b/sklearn/model_selection/_validation.py @@ -594,7 +594,7 @@ def _fit_and_score(estimator, X, y, scorer, train, test, verbose, else: estimator.fit(X_train, y_train, **fit_params) - except Exception as e: + except Exception: # Note fit time as time until error fit_time = time.time() - start_time score_time = 0.0 diff --git a/sklearn/multiclass.py b/sklearn/multiclass.py index ad420506a9694..b56759bb68a4a 100644 --- a/sklearn/multiclass.py +++ b/sklearn/multiclass.py @@ -481,11 +481,12 @@ def n_classes_(self): # TODO: Remove coef_ attribute in 1.1 # mypy error: Decorated property not supported - @deprecated("Attribute coef_ was deprecated in " # type: ignore - "version 0.24 and will be removed in 1.1 (renaming of 0.26). " - "If you observe this warning while using RFE " - "or SelectFromModel, use the importance_getter " - "parameter instead.") + @deprecated( # type: ignore + "Attribute coef_ was deprecated in " + "version 0.24 and will be removed in 1.1 (renaming of 0.26). " + "If you observe this warning while using RFE " + "or SelectFromModel, use the importance_getter " + "parameter instead.") @property def coef_(self): check_is_fitted(self) @@ -499,11 +500,12 @@ def coef_(self): # TODO: Remove intercept_ attribute in 1.1 # mypy error: Decorated property not supported - @deprecated("Attribute intercept_ was deprecated in " # type: ignore - "version 0.24 and will be removed in 1.1 (renaming of 0.26). " - "If you observe this warning while using RFE " - "or SelectFromModel, use the importance_getter " - "parameter instead.") + @deprecated( # type: ignore + "Attribute intercept_ was deprecated in " + "version 0.24 and will be removed in 1.1 (renaming of 0.26). " + "If you observe this warning while using RFE " + "or SelectFromModel, use the importance_getter " + "parameter instead.") @property def intercept_(self): check_is_fitted(self) @@ -514,8 +516,9 @@ def intercept_(self): # TODO: Remove in 1.1 # mypy error: Decorated property not supported - @deprecated("Attribute _pairwise was deprecated in " # type: ignore - "version 0.24 and will be removed in 1.1 (renaming of 0.26).") + @deprecated( # type: ignore + "Attribute _pairwise was deprecated in " + "version 0.24 and will be removed in 1.1 (renaming of 0.26).") @property def _pairwise(self): """Indicate if wrapped estimator is using a precomputed Gram matrix""" @@ -794,8 +797,9 @@ def n_classes_(self): # TODO: Remove in 1.1 # mypy error: Decorated property not supported - @deprecated("Attribute _pairwise was deprecated in " # type: ignore - "version 0.24 and will be removed in 1.1 (renaming of 0.26).") + @deprecated( # type: ignore + "Attribute _pairwise was deprecated in " + "version 0.24 and will be removed in 1.1 (renaming of 0.26).") @property def _pairwise(self): """Indicate if wrapped estimator is using a precomputed Gram matrix""" diff --git a/sklearn/naive_bayes.py b/sklearn/naive_bayes.py index 7c46a771a2fd4..74de146abba9b 100644 --- a/sklearn/naive_bayes.py +++ b/sklearn/naive_bayes.py @@ -674,16 +674,18 @@ def _init_counters(self, n_classes, n_features): dtype=np.float64) # mypy error: Decorated property not supported - @deprecated("Attribute coef_ was deprecated in " # type: ignore - "version 0.24 and will be removed in 1.1 (renaming of 0.26).") + @deprecated( # type: ignore + "Attribute coef_ was deprecated in " + "version 0.24 and will be removed in 1.1 (renaming of 0.26).") @property def coef_(self): return (self.feature_log_prob_[1:] if len(self.classes_) == 2 else self.feature_log_prob_) # mypy error: Decorated property not supported - @deprecated("Attribute intercept_ was deprecated in " # type: ignore - "version 0.24 and will be removed in 1.1 (renaming of 0.26).") + @deprecated( # type: ignore + "Attribute intercept_ was deprecated in " + "version 0.24 and will be removed in 1.1 (renaming of 0.26).") @property def intercept_(self): return (self.class_log_prior_[1:] diff --git a/sklearn/neighbors/_base.py b/sklearn/neighbors/_base.py index c6438165aba1a..99c25686da216 100644 --- a/sklearn/neighbors/_base.py +++ b/sklearn/neighbors/_base.py @@ -526,8 +526,9 @@ def _more_tags(self): # TODO: Remove in 1.1 # mypy error: Decorated property not supported - @deprecated("Attribute _pairwise was deprecated in " # type: ignore - "version 0.24 and will be removed in 1.1 (renaming of 0.26).") + @deprecated( # type: ignore + "Attribute _pairwise was deprecated in " + "version 0.24 and will be removed in 1.1 (renaming of 0.26).") @property def _pairwise(self): # For cross-validation routines to split data correctly diff --git a/sklearn/neighbors/_kde.py b/sklearn/neighbors/_kde.py index 1ebd713b16e69..53af66921da76 100644 --- a/sklearn/neighbors/_kde.py +++ b/sklearn/neighbors/_kde.py @@ -289,6 +289,6 @@ def _more_tags(self): return { '_xfail_checks': { 'check_sample_weights_invariance': - 'sample_weight must have positive values', + ('sample_weight must have positive values'), } } diff --git a/sklearn/neighbors/_regression.py b/sklearn/neighbors/_regression.py index 64a4e3df8fcae..1358b116a0926 100644 --- a/sklearn/neighbors/_regression.py +++ b/sklearn/neighbors/_regression.py @@ -163,8 +163,9 @@ def _more_tags(self): # TODO: Remove in 1.1 # mypy error: Decorated property not supported - @deprecated("Attribute _pairwise was deprecated in " # type: ignore - "version 0.24 and will be removed in 1.1 (renaming of 0.26).") + @deprecated( # type: ignore + "Attribute _pairwise was deprecated in " + "version 0.24 and will be removed in 1.1 (renaming of 0.26).") @property def _pairwise(self): # For cross-validation routines to split data correctly diff --git a/sklearn/neural_network/_rbm.py b/sklearn/neural_network/_rbm.py index 42a9eb81e30cd..b2a15ed79587d 100644 --- a/sklearn/neural_network/_rbm.py +++ b/sklearn/neural_network/_rbm.py @@ -389,8 +389,8 @@ def _more_tags(self): return { '_xfail_checks': { 'check_methods_subset_invariance': - 'fails for the decision_function method', + ('fails for the decision_function method'), 'check_methods_sample_order_invariance': - 'fails for the score_samples method', + ('fails for the score_samples method'), } } diff --git a/sklearn/pipeline.py b/sklearn/pipeline.py index 45ba5546ccfc0..e2449f781a105 100644 --- a/sklearn/pipeline.py +++ b/sklearn/pipeline.py @@ -650,8 +650,9 @@ def _more_tags(self): # TODO: Remove in 1.1 # mypy error: Decorated property not supported - @deprecated("Attribute _pairwise was deprecated in " # type: ignore - "version 0.24 and will be removed in 1.1 (renaming of 0.26).") + @deprecated( # type: ignore + "Attribute _pairwise was deprecated in " + "version 0.24 and will be removed in 1.1 (renaming of 0.26).") @property def _pairwise(self): # check if first estimator expects pairwise input diff --git a/sklearn/preprocessing/_data.py b/sklearn/preprocessing/_data.py index 82e6d5d85ec19..bd507bb69976d 100644 --- a/sklearn/preprocessing/_data.py +++ b/sklearn/preprocessing/_data.py @@ -2105,8 +2105,9 @@ def _more_tags(self): # TODO: Remove in 1.1 # mypy error: Decorated property not supported - @deprecated("Attribute _pairwise was deprecated in " # type: ignore - "version 0.24 and will be removed in 1.1.") + @deprecated( # type: ignore + "Attribute _pairwise was deprecated in " + "version 0.24 and will be removed in 1.1.") @property def _pairwise(self): return True diff --git a/sklearn/svm/_base.py b/sklearn/svm/_base.py index 62710ec5157fb..6ee3439dbf097 100644 --- a/sklearn/svm/_base.py +++ b/sklearn/svm/_base.py @@ -109,8 +109,9 @@ def _more_tags(self): # TODO: Remove in 1.1 # mypy error: Decorated property not supported - @deprecated("Attribute _pairwise was deprecated in " # type: ignore - "version 0.24 and will be removed in 1.1 (renaming of 0.26).") + @deprecated( # type: ignore + "Attribute _pairwise was deprecated in " + "version 0.24 and will be removed in 1.1 (renaming of 0.26).") @property def _pairwise(self): # Used by cross_val_score. diff --git a/sklearn/svm/_classes.py b/sklearn/svm/_classes.py index 8946e77ef905f..f278a28b04c0e 100644 --- a/sklearn/svm/_classes.py +++ b/sklearn/svm/_classes.py @@ -251,7 +251,7 @@ def _more_tags(self): return { '_xfail_checks': { 'check_sample_weights_invariance': - 'zero sample_weight is not equivalent to removing samples', + ('zero sample_weight is not equivalent to removing samples'), } } @@ -441,7 +441,7 @@ def _more_tags(self): return { '_xfail_checks': { 'check_sample_weights_invariance': - 'zero sample_weight is not equivalent to removing samples', + ('zero sample_weight is not equivalent to removing samples'), } } @@ -677,7 +677,7 @@ def _more_tags(self): return { '_xfail_checks': { 'check_sample_weights_invariance': - 'zero sample_weight is not equivalent to removing samples', + ('zero sample_weight is not equivalent to removing samples'), } } @@ -901,10 +901,10 @@ def _more_tags(self): return { '_xfail_checks': { 'check_methods_subset_invariance': - 'fails for the decision_function method', - 'check_class_weight_classifiers': 'class_weight is ignored.', + ('fails for the decision_function method'), + 'check_class_weight_classifiers': ('class_weight is ignored.'), 'check_sample_weights_invariance': - 'zero sample_weight is not equivalent to removing samples', + ('zero sample_weight is not equivalent to removing samples'), } } @@ -1067,7 +1067,7 @@ def _more_tags(self): return { '_xfail_checks': { 'check_sample_weights_invariance': - 'zero sample_weight is not equivalent to removing samples', + ('zero sample_weight is not equivalent to removing samples'), } } @@ -1224,7 +1224,7 @@ def _more_tags(self): return { '_xfail_checks': { 'check_sample_weights_invariance': - 'zero sample_weight is not equivalent to removing samples', + ('zero sample_weight is not equivalent to removing samples'), } } @@ -1449,6 +1449,6 @@ def _more_tags(self): return { '_xfail_checks': { 'check_sample_weights_invariance': - 'zero sample_weight is not equivalent to removing samples', + ('zero sample_weight is not equivalent to removing samples'), } } diff --git a/sklearn/tests/test_docstring_parameters.py b/sklearn/tests/test_docstring_parameters.py index 83de4253794b6..3a8c2f8190606 100644 --- a/sklearn/tests/test_docstring_parameters.py +++ b/sklearn/tests/test_docstring_parameters.py @@ -33,11 +33,12 @@ # FutureWarnings with warnings.catch_warnings(): warnings.simplefilter('ignore', FutureWarning) + # mypy error: Module has no attribute "__path__" + sklearn_path = sklearn.__path__ # type: ignore # mypy issue #1422 PUBLIC_MODULES = set([ pckg[1] for pckg in walk_packages( prefix='sklearn.', - # mypy error: Module has no attribute "__path__" - path=sklearn.__path__) # type: ignore # mypy issue #1422 + path=sklearn_path) if not ("._" in pckg[1] or ".tests." in pckg[1]) ]) diff --git a/sklearn/tests/test_random_projection.py b/sklearn/tests/test_random_projection.py index 79d2af5776859..3906160b67b3b 100644 --- a/sklearn/tests/test_random_projection.py +++ b/sklearn/tests/test_random_projection.py @@ -260,12 +260,12 @@ def test_random_projection_embedding_quality(): assert 1 - eps < distances_ratio.min() -def test_SparseRandomProjection_output_representation(): - for SparseRandomProjection in all_SparseRandomProjection: +def test_SparseRandomProj_output_representation(): + for SparseRandomProj in all_SparseRandomProjection: # when using sparse input, the projected data can be forced to be a # dense numpy array - rp = SparseRandomProjection(n_components=10, dense_output=True, - random_state=0) + rp = SparseRandomProj(n_components=10, dense_output=True, + random_state=0) rp.fit(data) assert isinstance(rp.transform(data), np.ndarray) @@ -273,8 +273,8 @@ def test_SparseRandomProjection_output_representation(): assert isinstance(rp.transform(sparse_data), np.ndarray) # the output can be left to a sparse matrix instead - rp = SparseRandomProjection(n_components=10, dense_output=False, - random_state=0) + rp = SparseRandomProj(n_components=10, dense_output=False, + random_state=0) rp = rp.fit(data) # output for dense input will stay dense: assert isinstance(rp.transform(data), np.ndarray)