Skip to content

Commit 2bc9601

Browse files
authored
MAINT use isort for imports (#948)
1 parent 4714869 commit 2bc9601

File tree

106 files changed

+386
-491
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

106 files changed

+386
-491
lines changed

.pre-commit-config.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,7 @@ repos:
2020
- id: mypy
2121
files: sklearn/
2222
additional_dependencies: [pytest==6.2.4]
23+
- repo: https://github.com/PyCQA/isort
24+
rev: 5.10.1
25+
hooks:
26+
- id: isort

azure-pipelines.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,14 @@ jobs:
4545
versionSpec: '3.9'
4646
- bash: |
4747
# Include pytest compatibility with mypy
48-
pip install pytest flake8 mypy==0.782 black==22.3
48+
pip install pytest flake8 mypy==0.782 black==22.3 isort
4949
displayName: Install linters
5050
- bash: |
5151
black --check --diff .
5252
displayName: Run black
53+
- bash: |
54+
isort --check --diff .
55+
displayName: Run isort
5356
- bash: |
5457
./build_tools/azure/linting.sh
5558
displayName: Run linting

conftest.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
# rather than the one from site-packages.
77

88
import os
9+
910
import pytest
1011

1112

doc/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
import os
1616
import sys
1717
from datetime import datetime
18-
from pathlib import Path
1918
from io import StringIO
19+
from pathlib import Path
2020

2121
# If extensions (or modules to document with autodoc) are in another directory,
2222
# add these directories to sys.path here. If the directory is relative to the

doc/sphinxext/github_link.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
from operator import attrgetter
21
import inspect
3-
import subprocess
42
import os
3+
import subprocess
54
import sys
65
from functools import partial
6+
from operator import attrgetter
77

88
REVISION_CMD = "git rev-parse --short HEAD"
99

examples/api/plot_sampling_strategy_usage.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
# %%
2828
from sklearn.datasets import load_iris
29+
2930
from imblearn.datasets import make_imbalance
3031

3132
iris = load_iris(as_frame=True)

examples/applications/plot_impact_imbalanced_classes.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,10 @@
6060
# As a baseline, we could use a classifier which will always predict the
6161
# majority class independently of the features provided.
6262

63+
from sklearn.dummy import DummyClassifier
64+
6365
# %%
6466
from sklearn.model_selection import cross_validate
65-
from sklearn.dummy import DummyClassifier
6667

6768
dummy_clf = DummyClassifier(strategy="most_frequent")
6869
scoring = ["accuracy", "balanced_accuracy"]
@@ -121,9 +122,8 @@
121122

122123
# %%
123124
from sklearn.impute import SimpleImputer
124-
from sklearn.preprocessing import StandardScaler
125-
from sklearn.preprocessing import OneHotEncoder
126125
from sklearn.pipeline import make_pipeline
126+
from sklearn.preprocessing import OneHotEncoder, StandardScaler
127127

128128
num_pipe = make_pipeline(
129129
StandardScaler(), SimpleImputer(strategy="mean", add_indicator=True)
@@ -139,8 +139,8 @@
139139
# numerical pipeline
140140

141141
# %%
142-
from sklearn.compose import make_column_transformer
143142
from sklearn.compose import make_column_selector as selector
143+
from sklearn.compose import make_column_transformer
144144

145145
preprocessor_linear = make_column_transformer(
146146
(num_pipe, selector(dtype_include="number")),
@@ -176,9 +176,10 @@
176176
# classifier, we will not need to scale the numerical data, and we will only
177177
# need to ordinal encode the categorical data.
178178

179+
from sklearn.ensemble import RandomForestClassifier
180+
179181
# %%
180182
from sklearn.preprocessing import OrdinalEncoder
181-
from sklearn.ensemble import RandomForestClassifier
182183

183184
num_pipe = SimpleImputer(strategy="mean", add_indicator=True)
184185
cat_pipe = make_pipeline(
@@ -336,8 +337,9 @@
336337
# applying a single random under-sampling. We will use a gradient-boosting
337338
# classifier within a :class:`~imblearn.ensemble.BalancedBaggingClassifier`.
338339

339-
from sklearn.experimental import enable_hist_gradient_boosting # noqa
340340
from sklearn.ensemble import HistGradientBoostingClassifier
341+
from sklearn.experimental import enable_hist_gradient_boosting # noqa
342+
341343
from imblearn.ensemble import BalancedBaggingClassifier
342344

343345
bag_clf = make_pipeline(

examples/applications/plot_multi_class_under_sampling.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@
2020
from sklearn.preprocessing import StandardScaler
2121

2222
from imblearn.datasets import make_imbalance
23-
from imblearn.under_sampling import NearMiss
24-
from imblearn.pipeline import make_pipeline
2523
from imblearn.metrics import classification_report_imbalanced
24+
from imblearn.pipeline import make_pipeline
25+
from imblearn.under_sampling import NearMiss
2626

2727
print(__doc__)
2828

examples/applications/plot_outlier_rejections.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,9 @@
1313
# Authors: Guillaume Lemaitre <[email protected]>
1414
# License: MIT
1515

16-
import numpy as np
1716
import matplotlib.pyplot as plt
18-
19-
from sklearn.datasets import make_moons, make_blobs
17+
import numpy as np
18+
from sklearn.datasets import make_blobs, make_moons
2019
from sklearn.ensemble import IsolationForest
2120
from sklearn.linear_model import LogisticRegression
2221
from sklearn.metrics import classification_report

examples/applications/plot_over_sampling_benchmark_lfw.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,12 @@
7272
#
7373
# We will create different pipelines and evaluate them.
7474

75+
from sklearn.neighbors import KNeighborsClassifier
76+
7577
# %%
7678
from imblearn import FunctionSampler
77-
from imblearn.over_sampling import ADASYN, RandomOverSampler, SMOTE
79+
from imblearn.over_sampling import ADASYN, SMOTE, RandomOverSampler
7880
from imblearn.pipeline import make_pipeline
79-
from sklearn.neighbors import KNeighborsClassifier
8081

8182
classifier = KNeighborsClassifier(n_neighbors=3)
8283

@@ -98,7 +99,7 @@
9899
# cross-validation.
99100

100101
# %%
101-
from sklearn.metrics import RocCurveDisplay, roc_curve, auc
102+
from sklearn.metrics import RocCurveDisplay, auc, roc_curve
102103

103104
disp = []
104105
for model in pipeline:

0 commit comments

Comments
 (0)