8000 MNT Apply ruff/flake8-implicit-str-concat rules (ISC) (#30695) · scikit-learn/scikit-learn@5cdbbf1 · GitHub
[go: up one dir, main page]

Skip to content

Commit 5cdbbf1

Browse files
MNT Apply ruff/flake8-implicit-str-concat rules (ISC) (#30695)
Co-authored-by: Yao Xiao <108576690+Charlie-XIAO@users.noreply.github.com>
1 parent efc355e commit 5cdbbf1

26 files changed

+58
-62
lines changed

build_tools/get_comment.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,8 @@ def get_step_message(log, start, end, title, message, details):
5656
return ""
5757
res = (
5858
"-----------------------------------------------\n"
59-
+ f"### {title}\n\n"
60-
+ message
61-
+ "\n\n"
59+
f"### {title}\n\n"
60+
f"{message}\n\n"
6261
)
6362
if details:
6463
res += (

examples/classification/plot_lda.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,10 @@ def generate_data(n_samples, n_features):
9898
plt.legend(loc="lower left")
9999
plt.ylim((0.65, 1.0))
100100
plt.suptitle(
101-
"LDA (Linear Discriminant Analysis) vs. "
102-
+ "\n"
103-
+ "LDA with Ledoit Wolf vs. "
104-
+ "\n"
105-
+ "LDA with OAS (1 discriminative feature)"
101+
"LDA (Linear Discriminant Analysis) vs."
102+
"\n"
103+
"LDA with Ledoit Wolf vs."
104+
"\n"
105+
"LDA with OAS (1 discriminative feature)"
106106
)
107107
plt.show()

examples/cluster/plot_cluster_comparison.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -224,14 +224,14 @@
224224
warnings.filterwarnings(
225225
"ignore",
226226
message="the number of connected components of the "
227-
+ "connectivity matrix is [0-9]{1,2}"
228-
+ " > 1. Completing it to avoid stopping the tree early.",
227+
"connectivity matrix is [0-9]{1,2}"
228+
" > 1. Completing it to avoid stopping the tree early.",
229229
category=UserWarning,
230230
)
231231
warnings.filterwarnings(
232232
"ignore",
233233
message="Graph is not fully connected, spectral embedding"
234-
+ " may not work as expected.",
234+
" may not work as expected.",
235235
category=UserWarning,
236236
)
237237
algorithm.fit(X)

examples/cluster/plot_linkage_comparison.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,8 @@
123123
warnings.filterwarnings(
124124
"ignore",
125125
message="the number of connected components of the "
126-
+ "connectivity matrix is [0-9]{1,2}"
127-
+ " > 1. Completing it to avoid stopping the tree early.",
126+
"connectivity matrix is [0-9]{1,2}"
127+
" > 1. Completing it to avoid stopping the tree early.",
128128
category=UserWarning,
129129
)
130130
algorithm.fit(X)

examples/kernel_approximation/plot_scalable_poly_kernels.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@
143143
}
144144
print(
145145
f"Linear SVM score on {n_components} PolynomialCountSketch "
146-
+ f"features: {ps_lsvm_score:.2f}%"
146+
f"features: {ps_lsvm_score:.2f}%"
147147
)
148148

149149
# %%

examples/mixture/plot_concentration_prior.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ def plot_results(ax1, ax2, estimator, X, y, title, plot_title=False):
103103
# mean_precision_prior= 0.8 to minimize the influence of the prior
104104
estimators = [
105105
(
106-
"Finite mixture with a Dirichlet distribution\nprior and " r"$\gamma_0=$",
106+
"Finite mixture with a Dirichlet distribution\n" r"prior and $\gamma_0=$",
107107
BayesianGaussianMixture(
108108
weight_concentration_prior_type="dirichlet_distribution",
109109
n_components=2 * n_components,
@@ -116,7 +116,7 @@ def plot_results(ax1, ax2, estimator, X, y, title, plot_title=False):
116116
[0.001, 1, 1000],
117117
),
118118
(
119-
"Infinite mixture with a Dirichlet process\n prior and" r"$\gamma_0=$",
119+
"Infinite mixture with a Dirichlet process\n" r"prior and $\gamma_0=$",
120120
BayesianGaussianMixture(
121121
weight_concentration_prior_type="dirichlet_process",
122122
n_components=2 * n_components,

maint_tools/sort_whats_new.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def entry_sort_key(s):
2323

2424
for entry in re.split("\n(?=- )", text.strip()):
2525
modules = re.findall(
26-
r":(?:func|meth|mod|class):" r"`(?:[^<`]*<|~)?(?:sklearn.)?([a-z]\w+)", entry
26+
r":(?:func|meth|mod|class):`(?:[^<`]*<|~)?(?:sklearn.)?([a-z]\w+)", entry
2727
)
2828
modules = set(modules)
2929
if len(modules) > 1:

sklearn/base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@ def _clone_parametrized(estimator, *, safe=True):
110110
if isinstance(estimator, type):
111111
raise TypeError(
112112
"Cannot clone object. "
113-
+ "You should provide an instance of "
114-
+ "scikit-learn estimator instead of a class."
113+
"You should provide an instance of "
114+
"scikit-learn estimator instead of a class."
115115
)
116116
else:
117117
raise TypeError(

sklearn/compose/tests/test_target.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def test_transform_target_regressor_error():
3636
)
3737
with pytest.raises(
3838
TypeError,
39-
match=r"fit\(\) got an unexpected " "keyword argument 'sample_weight'",
39+
match=r"fit\(\) got an unexpected keyword argument 'sample_weight'",
4040
):
4141
regr.fit(X, y, sample_weight=sample_weight)
4242

sklearn/datasets/_twenty_newsgroups.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ def strip_newsgroup_header(text):
115115

116116

117117
_QUOTE_RE = re.compile(
118-
r"(writes in|writes:|wrote:|says:|said:" r"|^In article|^Quoted from|^\||^>)"
118+
r"(writes in|writes:|wrote:|says:|said:|^In article|^Quoted from|^\||^>)"
119119
)
120120

121121

sklearn/datasets/tests/test_samples_generator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -689,7 +689,7 @@ def test_make_moons_unbalanced():
689689

690690
with pytest.raises(
691691
ValueError,
692-
match=r"`n_samples` can be either an int " r"or a two-element tuple.",
692+
match=r"`n_samples` can be either an int or a two-element tuple.",
693693
):
694694
make_moons(n_samples=(10,))
695695

sklearn/decomposition/_factor_analysis.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -295,8 +295,8 @@ def my_svd(X):
295295
else:
296296
warnings.warn(
297297
"FactorAnalysis did not converge."
298-
+ " You might want"
299-
+ " to increase the number of iterations.",
298+
" You might want"
299+
" to increase the number of iterations.",
300300
ConvergenceWarning,
301301
)
302302

sklearn/decomposition/tests/test_fastica.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ def test_fastica_errors():
367367
with pytest.raises(ValueError, match=r"alpha must be in \[1,2\]"):
368368
fastica(X, fun_args={"alpha": 0})
369369
with pytest.raises(
370-
ValueError, match="w_init has invalid shape.+" r"should be \(3L?, 3L?\)"
370+
ValueError, match=r"w_init has invalid shape.+should be \(3L?, 3L?\)"
371371
):
372372
fastica(X, w_init=w_init)
373373

sklearn/feature_selection/_base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,8 +260,8 @@ def _get_feature_importances(estimator, getter, transform_func=None, norm_order=
260260
else:
261261
raise ValueError(
262262
"Valid values for `transform_func` are "
263-
+ "None, 'norm' and 'square'. Those two "
264-
+ "transformation are only supported now"
263+
"None, 'norm' and 'square'. Those two "
264+
"transformation are only supported now"
265265
)
266266

267267
return importances

sklearn/inspection/_plot/tests/test_plot_partial_dependence.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1186,9 +1186,9 @@ def test_plot_partial_dependence_lines_kw(
11861186
)
11871187

11881188
line = disp.lines_[0, 0, -1]
1189-
assert line.get_color() == expected_colors[0], (
1190-
f"{line.get_color()}!={expected_colors[0]}\n" f"{line_kw} and {pd_line_kw}"
1191-
)
1189+
assert (
1190+
line.get_color() == expected_colors[0]
1191+
), f"{line.get_color()}!={expected_colors[0]}\n{line_kw} and {pd_line_kw}"
11921192
if pd_line_kw is not None:
11931193
if "linestyle" in pd_line_kw:
11941194
assert line.get_linestyle() == pd_line_kw["linestyle"]

sklearn/linear_model/tests/test_ridge.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,7 @@ def test_ridge_regression_convergence_fail():
524524
rng = np.random.RandomState(0)
525525
y = rng.randn(5)
526526
X = rng.randn(5, 10)
527-
warning_message = r"sparse_cg did not converge after" r" [0-9]+ iterations."
527+
warning_message = r"sparse_cg did not converge after [0-9]+ iterations."
528528
with pytest.warns(ConvergenceWarning, match=warning_message):
529529
ridge_regression(
530530
X, y, alpha=1.0, solver="sparse_cg", tol=0.0, max_iter=None, verbose=1

sklearn/metrics/cluster/tests/test_supervised.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
def test_error_messages_on_wrong_input():
4141
for score_func in score_funcs:
4242
expected = (
43-
r"Found input variables with inconsistent numbers " r"of samples: \[2, 3\]"
43+
r"Found input variables with inconsistent numbers of samples: \[2, 3\]"
4444
)
4545
with pytest.raises(ValueError, match=expected):
4646
score_func([0, 1], [1, 1, 1])

sklearn/metrics/tests/test_common.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1801,7 +1801,7 @@ def test_metrics_pos_label_error_str(metric, y_pred_threshold, dtype_y_str):
18011801
"pass pos_label explicit"
18021802
)
18031803
err_msg_pos_label_1 = (
1804-
r"pos_label=1 is not a valid label. It should be one of " r"\['eggs', 'spam'\]"
1804+
r"pos_label=1 is not a valid label. It should be one of \['eggs', 'spam'\]"
18051805
)
18061806

18071807
pos_label_default = signature(metric).parameters["pos_label"].default

sklearn/metrics/tests/test_pairwise.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1528,7 +1528,7 @@ def test_pairwise_distances_data_derived_params_error(metric):
15281528

15291529
with pytest.raises(
15301530
ValueError,
1531-
match=rf"The '(V|VI)' parameter is required for the " rf"{metric} metric",
1531+
match=rf"The '(V|VI)' parameter is required for the {metric} metric",
15321532
):
15331533
pairwise_distances(X, Y, metric=metric)
15341534

sklearn/neighbors/tests/test_nca.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ def test_verbose(init_name, capsys):
401401
line,
402402
)
403403
assert re.match(
404-
r"\[NeighborhoodComponentsAnalysis\] Training took\ *" r"\d+\.\d{2}s\.",
404+
r"\[NeighborhoodComponentsAnalysis\] Training took\ *\d+\.\d{2}s\.",
405405
lines[-2],
406406
)
407407
assert lines[-1] == ""

sklearn/preprocessing/tests/test_data.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2279,7 +2279,7 @@ def test_power_transformer_shape_exception(method):
22792279
# Exceptions should be raised for arrays with different num_columns
22802280
# than during fitting
22812281
wrong_shape_message = (
2282-
r"X has \d+ features, but PowerTransformer is " r"expecting \d+ features"
2282+
r"X has \d+ features, but PowerTransformer is expecting \d+ features"
22832283
)
22842284

22852285
with pytest.raises(ValueError, match=wrong_shape_message):

sklearn/tests/test_docstring_parameters_consistency.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@
7070
by support \(the number of true instances for each label\)\. This
7171
alters 'macro' to account for label imbalance; it can result in an
7272
F-score that is not between precision and recall\."""
73-
+ r"[\s\w]*\.*" # optionally match additional sentence
74-
+ r"""
73+
r"[\s\w]*\.*" # optionally match additional sentence
74+
r"""
7575
``'samples'``:
7676
Calculate metrics for each instance, and find their average \(only
7777
meaningful for multilabel classification where this differs from

sklearn/tests/test_min_dependencies_readme.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ def test_min_dependencies_readme():
3333

3434
pattern = re.compile(
3535
r"(\.\. \|)"
36-
+ r"(([A-Za-z]+\-?)+)"
37-
+ r"(MinVersion\| replace::)"
38-
+ r"( [0-9]+\.[0-9]+(\.[0-9]+)?)"
36+
r"(([A-Za-z]+\-?)+)"
37+
r"(MinVersion\| replace::)"
38+
r"( [0-9]+\.[0-9]+(\.[0-9]+)?)"
3939
)
4040

4141
readme_path = Path(sklearn.__file__).parent.parent

sklearn/utils/estimator_checks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2317,7 +2317,7 @@ def check_estimators_empty_data_messages(name, estimator_orig):
23172317
# the following y should be accepted by both classifiers and regressors
23182318
# and ignored by unsupervised models
23192319
y = _enforce_estimator_tags_y(e, np.array([1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0]))
2320-
msg = r"0 feature\(s\) \(shape=\(\d*, 0\)\) while a minimum of \d* " "is required."
2320+
msg = r"0 feature\(s\) \(shape=\(\d*, 0\)\) while a minimum of \d* is required."
23212321
with raises(ValueError, match=msg):
23222322
e.fit(X_zero_features, y)
23232323

sklearn/utils/tests/test_testing.py

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -443,8 +443,7 @@ def test_check_docstring_parameters():
443443
"+ ['a', 'b']",
444444
],
445445
[
446-
"In function: "
447-
+ "sklearn.utils.tests.test_testing.f_too_many_param_docstring",
446+
"In function: sklearn.utils.tests.test_testing.f_too_many_param_docstring",
448447
(
449448
"Parameters in function docstring have more items w.r.t. function"
450449
" signature, first extra item: c"
@@ -475,8 +474,7 @@ def test_check_docstring_parameters():
475474
"+ []",
476475
],
477476
[
478-
"In function: "
479-
+ f"sklearn.utils.tests.test_testing.{mock_meta_name}.predict",
477+
f"In function: sklearn.utils.tests.test_testing.{mock_meta_name}.predict",
480478
(
481479
"There's a parameter name mismatch in function docstring w.r.t."
482480
" function signature, at index 0 diff: 'X' != 'y'"
@@ -489,21 +487,20 @@ def test_check_docstring_parameters():
489487
],
490488
[
491489
"In function: "
492-
+ f"sklearn.utils.tests.test_testing.{mock_meta_name}."
493-
+ "predict_proba",
490+
f"sklearn.utils.tests.test_testing.{mock_meta_name}."
491+
"predict_proba",
494492
"potentially wrong underline length... ",
495493
"Parameters ",
496494
"--------- in ",
497495
],
498496
[
499-
"In function: "
500-
+ f"sklearn.utils.tests.test_testing.{mock_meta_name}.score",
497+
f"In function: sklearn.utils.tests.test_testing.{mock_meta_name}.score",
501498
"potentially wrong underline length... ",
502499
"Parameters ",
503500
"--------- in ",
504501
],
505502
[
506-
"In function: " + f"sklearn.utils.tests.test_testing.{mock_meta_name}.fit",
503+
f"In function: sklearn.utils.tests.test_testing.{mock_meta_name}.fit",
507504
(
508505
"Parameters in function docstring have less items w.r.t. function"
509506
" signature, first missing item: X"
@@ -788,13 +785,13 @@ def test_assert_docstring_consistency_descr_regex_pattern():
788785
# Check regex that matches full parameter descriptions
789786
regex_full = (
790787
r"The (set|group) " # match 'set' or 'group'
791-
+ r"of labels to (include|add) " # match 'include' or 'add'
792-
+ r"when `average \!\= 'binary'`, and (their|the) " # match 'their' or 'the'
793-
+ r"order if `average is None`\."
794-
+ r"[\s\w]*\.* " # optionally match additional sentence
795-
+ r"Labels present (on|in) " # match 'on' or 'in'
796-
+ r"(them|the) " # match 'them' or 'the'
797-
+ r"datas? can be excluded\." # match 'data' or 'datas'
788+
r"of labels to (include|add) " # match 'include' or 'add'
789+
r"when `average \!\= 'binary'`, and (their|the) " # match 'their' or 'the'
790+
r"order if `average is None`\."
791+
r"[\s\w]*\.* " # optionally match additional sentence
792+
r"Labels present (on|in) " # match 'on' or 'in'
793+
r"(them|the) " # match 'them' or 'the'
794+
r"datas? can be excluded\." # match 'data' or 'datas'
798795
)
799796

800797
assert_docstring_consistency(

sklearn/utils/tests/test_validation.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -735,7 +735,7 @@ def test_check_array_accept_large_sparse_raise_exception(X_64bit):
735735

736736
def test_check_array_min_samples_and_features_messages():
737737
# empty list is considered 2D by default:
738-
msg = r"0 feature\(s\) \(shape=\(1, 0\)\) while a minimum of 1 is" " required."
738+
msg = r"0 feature\(s\) \(shape=\(1, 0\)\) while a minimum of 1 is required."
739739
with pytest.raises(ValueError, match=msg):
740740
check_array([[]])
741741

@@ -758,7 +758,7 @@ def test_check_array_min_samples_and_features_messages():
758758
# Simulate a model that would need at least 2 samples to be well defined
759759
X = np.ones((1, 10))
760760
y = np.ones(1)
761-
msg = r"1 sample\(s\) \(shape=\(1, 10\)\) while a minimum of 2 is" " required."
761+
msg = r"1 sample\(s\) \(shape=\(1, 10\)\) while a minimum of 2 is required."
762762
with pytest.raises(ValueError, match=msg):
763763
check_X_y(X, y, ensure_min_samples=2)
764764

@@ -771,7 +771,7 @@ def test_check_array_min_samples_and_features_messages():
771771
# with k=3)
772772
X = np.ones((10, 2))
773773
y = np.ones(2)
774-
msg = r"2 feature\(s\) \(shape=\(10, 2\)\) while a minimum of 3 is" " required."
774+
msg = r"2 feature\(s\) \(shape=\(10, 2\)\) while a minimum of 3 is required."
775775
with pytest.raises(ValueError, match=msg):
776776
check_X_y(X, y, ensure_min_features=3)
777777

@@ -784,7 +784,7 @@ def test_check_array_min_samples_and_features_messages():
784784
# 2D dataset.
785785
X = np.empty(0).reshape(10, 0)
786786
y = np.ones(10)
787-
msg = r"0 feature\(s\) \(shape=\(10, 0\)\) while a minimum of 1 is" " required."
787+
msg = r"0 feature\(s\) \(shape=\(10, 0\)\) while a minimum of 1 is required."
788788
with pytest.raises(ValueError, match=msg):
789789
check_X_y(X, y)
790790

0 commit comments

Comments
 (0)
0