8000 MNT Use list comprehension in place of list keyword (#23259) · scikit-learn/scikit-learn@93359b6 · GitHub
[go: up one dir, main page]

Skip to content

Commit 93359b6

Browse files
authored
MNT Use list comprehension in place of list keyword (#23259)
1 parent 452ede0 commit 93359b6

File tree

5 files changed

+14
-19
lines changed

5 files changed

+14
-19
lines changed

sklearn/datasets/_samples_generator.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1778,10 +1778,10 @@ def make_biclusters(
17781778
col_sizes = generator.multinomial(n_cols, np.repeat(1.0 / n_clusters, n_clusters))
17791779

17801780
row_labels = np.hstack(
1781-
list(np.repeat(val, rep) for val, rep in zip(range(n_clusters), row_sizes))
1781+
[np.repeat(val, rep) for val, rep in zip(range(n_clusters), row_sizes)]
17821782
)
17831783
col_labels = np.hstack(
1784-
list(np.repeat(val, rep) for val, rep in zip(range(n_clusters), col_sizes))
1784+
[np.repeat(val, rep) for val, rep in zip(range(n_clusters), col_sizes)]
17851785
)
17861786

17871787
result = np.zeros(shape, dtype=np.float64)
@@ -1881,10 +1881,10 @@ def make_checkerboard(
18811881
)
18821882

18831883
row_labels = np.hstack(
1884-
list(np.repeat(val, rep) for val, rep in zip(range(n_row_clusters), row_sizes))
1884+
[np.repeat(val, rep) for val, rep in zip(range(n_row_clusters), row_sizes)]
18851885
)
18861886
col_labels = np.hstack(
1887-
list(np.repeat(val, rep) for val, rep in zip(range(n_col_clusters), col_sizes))
1887+
[np.repeat(val, rep) for val, rep in zip(range(n_col_clusters), col_sizes)]
18881888
)
18891889

18901890
result = np.zeros(shape, dtype=np.float64)

sklearn/metrics/cluster/_bicluster.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,10 @@ def _pairwise_similarity(a, b, similarity):
3737
n_a = a_rows.shape[0]
3838
n_b = b_rows.shape[0]
3939
result = np.array(
40-
list(
41-
list(
42-
similarity(a_rows[i], a_cols[i], b_rows[j], b_cols[j])
43-
for j in range(n_b)
44-
)
40+
[
41+
[similarity(a_rows[i], a_cols[i], b_rows[j], b_cols[j]) for j in range(n_b)]
4542
for i in range(n_a)
46-
)
43+
]
4744
)
4845
return result
4946

sklearn/metrics/tests/test_classification.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,7 @@ def test(y_true, y_pred, string_type=False):
483483
)
484484

485485
test(y_true, y_pred)
486-
test(list(str(y) for y in y_true), list(str(y) for y in y_pred), string_type=True)
486+
test([str(y) for y in y_true], [str(y) for y in y_pred], string_type=True)
487487

488488

489489
def test_multilabel_confusion_matrix_multilabel():

sklearn/model_selection/tests/test_search.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1427,10 +1427,10 @@ def test_grid_search_correct_score_results():
14271427
for candidate_i, C in enumerate(Cs):
14281428
clf.set_params(C=C)
14291429
cv_scores = np.array(
1430-
list(
1430+
[
14311431
grid_search.cv_results_["split%d_test_score" % s][candidate_i]
14321432
for s in range(n_splits)
1433-
)
1433+
]
14341434
)
14351435
for i, (train, test) in enumerate(cv.split(X, y)):
14361436
clf.fit(X[train], y[train])
@@ -1584,9 +1584,7 @@ def test_grid_search_failing_classifier():
15841584
# that are expected to fail.
15851585
def get_cand_scores(i):
15861586
return np.array(
1587-
list(
1588-
gs.cv_results_["split%d_test_score" % s][i] for s in range(gs.n_splits_)
1589-
)
1587+
[gs.cv_results_["split%d_test_score" % s][i] for s in range(gs.n_splits_)]
15901588
)
15911589

15921590
assert all(
@@ -1840,10 +1838,10 @@ def _pop_time_keys(cv_results):
18401838
for score_type in ("train", "test"):
18411839
per_param_scores = {}
18421840
for param_i in range(4):
1843-
per_param_scores[param_i] = list(
1841+
per_param_scores[param_i] = [
18441842
gs.cv_results_["split%d_%s_score" % (s, score_type)][param_i]
18451843
for s in range(5)
1846-
)
1844+
]
18471845

18481846
assert_array_almost_equal(per_param_scores[0], per_param_scores[1])
18491847
assert_array_almost_equal(per_param_scores[2], per_param_scores[3])

sklearn/model_selection/tests/test_split.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1384,7 +1384,7 @@ def test_shufflesplit_reproducible():
13841384
# Check that iterating twice on the ShuffleSplit gives the same
13851385
# sequence of train-test when the random_state is given
13861386
ss = ShuffleSplit(random_state=21)
1387-
assert_array_equal(list(a for a, b in ss.split(X)), list(a for a, b in ss.split(X)))
1387+
assert_array_equal([a for a, b in ss.split(X)], [a for a, b in ss.split(X)])
13881388

13891389

13901390
def test_stratifiedshufflesplit_list_input():

0 commit comments

Comments
 (0)
0