8000 MNT Update ruff to 0.11.1 (#30976) · scikit-learn/scikit-learn@87d1e19 · GitHub
[go: up one dir, main page]

Skip to content

Commit 87d1e19

Browse files
MNT Update ruff to 0.11.1 (#30976)
1 parent 966782b commit 87d1e19

File tree

18 files changed

+35
-31
lines changed

18 files changed

+35
-31
lines changed

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ version: 2.1
33
jobs:
44
lint:
55
docker:
6-
- image: cimg/python:3.9.18
6+
- image: cimg/python:3.10.16
77
steps:
88
- checkout
99
- run:

.pre-commit-config.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ repos:
77
- id: end-of-file-fixer
88
- id: trailing-whitespace
99
- repo: https://github.com/astral-sh/ruff-pre-commit
10-
# Ruff version.
11-
rev: v0.5.1
10+
rev: v0.11.0
1211
hooks:
1312
- id: ruff
1413
args: ["--fix", "--output-format=full"]

build_tools/get_comment.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ def get_message(log_file, repo, pr_number, sha, run_id, details, versions):
116116
title="`ruff`",
117117
message=(
118118
"`ruff` detected issues. Please run "
119-
"`ruff check --fix --output-format=full .` locally, fix the remaining "
119+
"`ruff check --fix --output-format=full` locally, fix the remaining "
120120
"issues, and push the changes. Here you can see the detected issues. Note "
121121
f"that the installed `ruff` version is `ruff={versions['ruff']}`."
122122
),

build_tools/linting.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ else
2323
fi
2424

2525
echo -e "### Running ruff ###\n"
26-
ruff check --output-format=full .
26+
ruff check --output-format=full
2727
status=$?
2828
if [[ $status -eq 0 ]]
2929
then

pyproject.toml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ tests = [
8383
"pandas>=1.4.0",
8484
"pytest>=7.1.2",
8585
"pytest-cov>=2.9.0",
86-
"ruff>=0.5.1",
86+
"ruff>=0.11.0",
8787
"black>=24.3.0",
8888
"mypy>=1.15",
8989
"pyamg>=5.0.0",
@@ -126,7 +126,6 @@ exclude = '''
126126
[tool.ruff]
127127
# max line length for black
128128
line-length = 88
129-
target-version = "py38"
130129
exclude=[
131130
".git",
132131
"__pycache__",
@@ -146,7 +145,7 @@ exclude=[
146145
preview = true
147146
# This enables us to use the explicit preview rules that we want only
148147
explicit-preview-rules = true
149-
# all rules can be found here: https://beta.ruff.rs/docs/rules/
148+
# all rules can be found here: https://docs.astral.sh/ruff/rules/
150149
select = ["E", "F", "W", "I", "CPY001", "RUF"]
151150
ignore=[
152151
# space before : (needed for how black formats slicing)
@@ -155,11 +154,11 @@ ignore=[
155154
"E731",
156155
# do not use variables named 'l', 'O', or 'I'
157156
"E741",
158-
# E721 is in preview (july 2024) and gives many false positives.
157+
# E721 gives many false positives.
159158
# Use `is` and `is not` for type comparisons, or `isinstance()` for
160159
# isinstance checks
161160
"E721",
162-
# F841 is in preview (july 2024), and we don't care much about it.
161+
# We don't care much about F841.
163162
# Local variable ... is assigned to but never used
164163
"F841",
165164
# some RUF rules trigger too many changes

sklearn/_min_dependencies.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
"memory_profiler": ("0.57.0", "benchmark, docs"),
3333
"pytest": (PYTEST_MIN_VERSION, "tests"),
3434
"pytest-cov": ("2.9.0", "tests"),
35-
"ruff": ("0.5.1", "tests"),
35+
"ruff": ("0.11.0", "tests"),
3636
"black": ("24.3.0", "tests"),
3737
"mypy": ("1.15", "tests"),
3838
"pyamg": ("5.0.0", "tests"),

sklearn/datasets/tests/test_base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ def test_load_diabetes_raw():
255255
get an unscaled version when setting `scaled=False`."""
256256
diabetes_raw = load_diabetes(scaled=False)
257257
assert diabetes_raw.data.shape == (442, 10)
258-
assert diabetes_raw.target.size, 442
258+
assert diabetes_raw.target.size == 442
259259
assert len(diabetes_raw.feature_names) == 10
260260
assert diabetes_raw.DESCR
261261

sklearn/datasets/tests/test_samples_generator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ def test_make_classification_informative_features():
112112
(2, [1 / 2] * 2, 2),
113113
(2, [3 / 4, 1 / 4], 2),
114114
(10, [1 / 3] * 3, 10),
115-
(int(64), [1], 1),
115+
(64, [1], 1),
116116
]:
117117
n_classes = len(weights)
118118
n_clusters = n_classes * n_clusters_per_class

sklearn/decomposition/tests/test_incremental_pca.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Tests for Incremental PCA."""
22

3+
import itertools
34
import warnings
45

56
import numpy as np
@@ -228,7 +229,7 @@ def test_incremental_pca_batch_signs():
228229
ipca = IncrementalPCA(n_components=None, batch_size=batch_size).fit(X)
229230
all_components.append(ipca.components_)
230231

231-
for i, j in zip(all_components[:-1], all_components[1:]):
232+
for i, j in itertools.pairwise(all_components):
232233
assert_almost_equal(np.sign(i), np.sign(j), decimal=6)
233234

234235

@@ -265,7 +266,7 @@ def test_incremental_pca_batch_values():
265266
ipca = IncrementalPCA(n_components=None, batch_size=batch_size).fit(X)
266267
all_components.append(ipca.components_)
267268

268-
for i, j in zip(all_components[:-1], all_components[1:]):
269+
for i, j in itertools.pairwise(all_components):
269270
assert_almost_equal(i, j, decimal=1)
270271

271272

@@ -281,7 +282,7 @@ def test_incremental_pca_batch_rank():
281282
ipca = IncrementalPCA(n_components=20, batch_size=batch_size).fit(X)
282283
all_components.append(ipca.components_)
283284

284-
for components_i, components_j in zip(all_components[:-1], all_components[1:]):
285+
for components_i, components_j in itertools.pairwise(all_components):
285286
assert_allclose_dense_sparse(components_i, components_j)
286287

287288

@@ -300,7 +301,7 @@ def test_incremental_pca_partial_fit():
300301
pipca = IncrementalPCA(n_components=2, batch_size=batch_size)
301302
# Add one to make sure endpoint is included
302303
batch_itr = np.arange(0, n + 1, batch_size)
303-
for i, j in zip(batch_itr[:-1], batch_itr[1:]):
304+
for i, j in itertools.pairwise(batch_itr):
304305
pipca.partial_fit(X[i:j, :])
305306
assert_almost_equal(ipca.components_, pipca.components_, decimal=3)
306307

sklearn/ensemble/tests/test_forest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -926,7 +926,7 @@ def test_parallel_train():
926926

927927
X_test = rng.randn(n_samples, n_features)
928928
probas = [clf.predict_proba(X_test) for clf in clfs]
929-
for proba1, proba2 in zip(probas, probas[1:]):
929+
for proba1, proba2 in itertools.pairwise(probas):
930930
assert_array_almost_equal(proba1, proba2)
931931

932932

sklearn/manifold/tests/test_spectral_embedding.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import itertools
12
from unittest.mock import Mock
23

34
import numpy as np
@@ -71,7 +72,7 @@ def test_sparse_graph_connected_component(coo_container):
7172
p = rng.permutation(n_samples)
7273
connections = []
7374

74-
for start, stop in zip(boundaries[:-1], boundaries[1:]):
75+
for start, stop in itertools.pairwise(boundaries):
7576
group = p[start:stop]
7677
# Connect all elements within the group at least once via an
7778
# arbitrary path that spans the group.
@@ -91,7 +92,7 @@ def test_sparse_graph_connected_component(coo_container):
9192
affinity = coo_container((data, (row_idx, column_idx)))
9293
affinity = 0.5 * (affinity + affinity.T)
9394

94-
for start, stop in zip(boundaries[:-1], boundaries[1:]):
95+
for start, stop in itertools.pairwise(boundaries):
9596
component_1 = _graph_connected_component(affinity, p[start])
9697
component_size = stop - start
9798
assert component_1.sum() == component_size< 10000 /span>

sklearn/model_selection/tests/test_split.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -756,7 +756,7 @@ def test_shuffle_split():
756756
ss1 = ShuffleSplit(test_size=0.2, random_state=0).split(X)
757757
ss2 = ShuffleSplit(test_size=2, random_state=0).split(X)
758758
ss3 = ShuffleSplit(test_size=np.int32(2), random_state=0).split(X)
759-
ss4 = ShuffleSplit(test_size=int(2), random_state=0).split(X)
759+
ss4 = ShuffleSplit(test_size=2, random_state=0).split(X)
760760
for t1, t2, t3, t4 in zip(ss1, ss2, ss3, ss4):
761761
assert_array_equal(t1[0], t2[0])
762762
assert_array_equal(t2[0], t3[0])

sklearn/neural_network/_multilayer_perceptron.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import warnings
77
from abc import ABC, abstractmethod
8-
from itertools import chain
8+
from itertools import chain, pairwise
99
from numbers import Integral, Real
1010

1111
import numpy as np
@@ -491,7 +491,7 @@ def _fit(self, X, y, sample_weight=None, incremental=False):
491491

492492
coef_grads = [
493493
np.empty((n_fan_in_, n_fan_out_), dtype=X.dtype)
494-
for n_fan_in_, n_fan_out_ in zip(layer_units[:-1], layer_units[1:])
494+
for n_fan_in_, n_fan_out_ in pairwise(layer_units)
495495
]
496496

497497
intercept_grads = [

sklearn/tree/_classes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -322,12 +322,12 @@ def _fit(
322322
if isinstance(self.min_samples_leaf, numbers.Integral):
323323
min_samples_leaf = self.min_samples_leaf
324324
else: # float
325-
min_samples_leaf = int(ceil(self.min_samples_leaf * n_samples))
325+
min_samples_leaf = ceil(self.min_samples_leaf * n_samples)
326326

327327
if isinstance(self.min_samples_split, numbers.Integral):
328328
min_samples_split = self.min_samples_split
329329
else: # float
330-
min_samples_split = int(ceil(self.min_samples_split * n_samples))
330+
min_samples_split = ceil(self.min_samples_split * n_samples)
331331
min_samples_split = max(2, min_samples_split)
332332

333333
min_samples_split = max(min_samples_split, 2 * min_samples_leaf)

sklearn/tree/tests/test_tree.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import pickle
99
import re
1010
import struct
11-
from itertools import chain, product
11+
from itertools import chain, pairwise, product
1212

1313
import joblib
1414
import numpy as np
@@ -1865,7 +1865,7 @@ def assert_pruning_creates_subtree(estimator_cls, X, y, pruning_path):
18651865

18661866
# A pruned tree must be a subtree of the previous tree (which had a
18671867
# smaller ccp_alpha)
1868-
for prev_est, next_est in zip(estimators, estimators[1:]):
1868+
for prev_est, next_est in pairwise(estimators):
18691869
assert_is_subtree(prev_est.tree_, next_est.tree_)
18701870

18711871

sklearn/utils/_tags.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import warnings
44
from collections import OrderedDict
55
from dataclasses import dataclass, field
6-
from itertools import chain
6+
from itertools import chain, pairwise
77

88
from .fixes import _dataclass_args
99

@@ -437,7 +437,7 @@ def get_tags(estimator) -> Tags:
437437
# inheritance
438438
sklearn_tags_diff = {}
439439
items = list(sklearn_tags_provider.items())
440-
for current_item, next_item in zip(items[:-1], items[1:]):
440+
for current_item, next_item in pairwise(items):
441441
current_name, current_tags = current_item
442442
next_name, next_tags = next_item
443443
current_tags = _to_old_tags(current_tags)

sklearn/utils/sparsefuncs.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
# Authors: The scikit-learn developers
44
# SPDX-License-Identifier: BSD-3-Clause
55

6+
import itertools
7+
68
import numpy as np
79
import scipy.sparse as sp
810
from scipy.sparse.linalg import LinearOperator
@@ -704,7 +706,7 @@ def csc_median_axis_0(X):
704706
n_samples, n_features = X.shape
705707
median = np.zeros(n_features)
706708

707-
for f_ind, (start, end) in enumerate(zip(indptr[:-1], indptr[1:])):
709+
for f_ind, (start, end) in enumerate(itertools.pairwise(indptr)):
708710
# Prevent modifying X in place
709711
data = np.copy(X.data[start:end])
710712
nz = n_samples - data.size

sklearn/utils/tests/test_extmath.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Authors: The scikit-learn developers
22
# SPDX-License-Identifier: BSD-3-Clause
33

4+
import itertools
5+
46
import numpy as np
57
import pytest
68
from scipy import linalg, sparse
@@ -905,7 +907,7 @@ def test_incremental_variance_ddof():
905907
if steps[-1] != X.shape[0]:
906908
steps = np.hstack([steps, n_samples])
907909

908-
for i, j in zip(steps[:-1], steps[1:]):
910+
for i, j in itertools.pairwise(steps):
909911
batch = X[i:j, :]
910912
if i == 0:
911913
incremental_means = batch.mean(axis=0)

0 commit comments

Comments
 (0)
0