Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MNT Adds black config and fixes formatting before black #19031

Merged
merged 4 commits into from
Jun 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion benchmarks/bench_plot_fastkmeans.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions benchmarks/bench_plot_lasso_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/bench_plot_randomized_svd.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/bench_plot_svd.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions benchmarks/bench_rcv1_logreg_convergence.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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)
Expand Down
25 changes: 25 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
)/
)
'''
25 changes: 24 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion sklearn/calibration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
}
}

Expand Down
5 changes: 3 additions & 2 deletions sklearn/cluster/_affinity_propagation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
19 changes: 11 additions & 8 deletions sklearn/cluster/_kmeans.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
},
}

Expand Down Expand Up @@ -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"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We will get conflict with this: #19005
Do you think that we could merge #19005 first :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, lets merged that first.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#19005 is merged

" 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)
Expand Down Expand Up @@ -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'),
}
}
5 changes: 3 additions & 2 deletions sklearn/cluster/_spectral.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
7 changes: 4 additions & 3 deletions sklearn/decomposition/_dict_learning.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions sklearn/decomposition/_kernel_pca.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 3 additions & 3 deletions sklearn/ensemble/_gb.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion sklearn/ensemble/_iforest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
}
}

Expand Down
2 changes: 1 addition & 1 deletion sklearn/kernel_approximation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
}
5 changes: 3 additions & 2 deletions sklearn/kernel_ridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion sklearn/linear_model/_logistic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
}
}
2 changes: 1 addition & 1 deletion sklearn/linear_model/_ransac.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
}
}
2 changes: 1 addition & 1 deletion sklearn/linear_model/_ridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
}
}
4 changes: 2 additions & 2 deletions sklearn/linear_model/_stochastic_gradient.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
}
}

Expand Down Expand Up @@ -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'),
}
}

Expand Down
5 changes: 3 additions & 2 deletions sklearn/manifold/_mds.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
5 changes: 3 additions & 2 deletions sklearn/manifold/_spectral_embedding.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
13 changes: 5 additions & 8 deletions sklearn/metrics/tests/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
5 changes: 3 additions & 2 deletions sklearn/model_selection/_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion sklearn/model_selection/_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading