Skip to content

Commit b45a3e4

Browse files
glemaitrechkoar
authored andcommitted
Solving some pep8 (#207)
1 parent e6a857c commit b45a3e4

Some content is hidden

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

48 files changed

+2096
-2799
lines changed

build_tools/travis/flake8_diff.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,15 @@ echo -e '\nRunning flake8 on the diff in the range' "$COMMIT_RANGE" \
113113
"($(git rev-list $COMMIT_RANGE | wc -l) commit(s)):"
114114
echo '--------------------------------------------------------------------------------'
115115

116+
# We ignore files from sklearn/externals. Unfortunately there is no
117+
# way to do it with flake8 directly (the --exclude does not seem to
118+
# work with --diff). We could use the exclude magic in the git pathspec
119+
# ':!sklearn/externals' but it is only available on git 1.9 and Travis
120+
# uses git 1.8.
121+
# We need the following command to exit with 0 hence the echo in case
122+
# there is no match
123+
MODIFIED_FILES="$(git diff --name-only $COMMIT_RANGE || echo "no_match")"
124+
116125
check_files() {
117126
files="$1"
118127
options="$2"
@@ -121,4 +130,8 @@ check_files() {
121130
git diff --unified=0 $COMMIT_RANGE -- $files | flake8 --diff --show-source $options
122131
}
123132

133+
check_files "$(echo "$MODIFIED_FILES" | grep -v ^examples)"
134+
# Examples are allowed to not have imports at top of file
135+
check_files "$(echo "$MODIFIED_FILES" | grep ^examples)" --ignore=E402
136+
124137
echo -e "No problem detected by flake8\n"

build_tools/travis/install.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,5 +52,5 @@ cd $TRAVIS_BUILD_DIR
5252
python setup.py develop
5353

5454
if [[ "$RUN_FLAKE8" == "true" ]]; then
55-
conda install --yes flake8
55+
pip install flake8
5656
fi

imblearn/__init__.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,7 @@
3030
CHECK_CACHE_VERSION = True
3131

3232
# list all submodules available in imblearn and version
33-
__all__ = ['combine',
34-
'ensemble',
35-
'over_sampling',
36-
'under_sampling',
37-
'pipeline',
38-
'__version__']
33+
__all__ = [
34+
'combine', 'ensemble', 'over_sampling', 'under_sampling', 'pipeline',
35+
'__version__'
36+
]

imblearn/base.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717

1818
class SamplerMixin(six.with_metaclass(ABCMeta, BaseEstimator)):
19-
2019
"""Mixin class for samplers with abstact method.
2120
2221
Warning: This class should not be used directly. Use the derive classes
@@ -113,8 +112,8 @@ def fit(self, X, y):
113112
self.min_c_ = min(self.stats_c_, key=self.stats_c_.get)
114113
self.maj_c_ = max(self.stats_c_, key=self.stats_c_.get)
115114

116-
self.logger.info('%s classes detected: %s', np.unique(y).size,
117-
self.stats_c_)
115+
self.logger.info('%s classes detected: %s',
116+
np.unique(y).size, self.stats_c_)
118117

119118
# Check if the ratio provided at initialisation make sense
120119
if isinstance(self.ratio, float):

imblearn/combine/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,4 @@
55
from .smote_enn import SMOTEENN
66
from .smote_tomek import SMOTETomek
77

8-
__all__ = ['SMOTEENN',
9-
'SMOTETomek']
8+
__all__ = ['SMOTEENN', 'SMOTETomek']

imblearn/combine/smote_enn.py

Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -119,11 +119,10 @@ class SMOTEENN(BaseBinarySampler):
119119
120120
>>> from collections import Counter
121121
>>> from sklearn.datasets import make_classification
122-
>>> from imblearn.combine import SMOTEENN
123-
>>> X, y = make_classification(n_classes=2, class_sep=2, weights=[0.1, 0.9],
124-
... n_informative=3, n_redundant=1, flip_y=0,
125-
... n_features=20, n_clusters_per_class=1,
126-
... n_samples=1000, random_state=10)
122+
>>> from imblearn.combine import SMOTEENN # doctest: +NORMALIZE_WHITESPACE
123+
>>> X, y = make_classification(n_classes=2, class_sep=2,
124+
... weights=[0.1, 0.9], n_informative=3, n_redundant=1, flip_y=0,
125+
... n_features=20, n_clusters_per_class=1, n_samples=1000, random_state=10)
127126
>>> print('Original dataset shape {}'.format(Counter(y)))
128127
Original dataset shape Counter({1: 900, 0: 100})
129128
>>> sme = SMOTEENN(random_state=42)
@@ -139,10 +138,19 @@ class SMOTEENN(BaseBinarySampler):
139138
140139
"""
141140

142-
def __init__(self, ratio='auto', random_state=None,
143-
smote=None, enn=None,
144-
k=None, m=None, out_step=None, kind_smote=None,
145-
size_ngh=None, n_neighbors=None, kind_enn=None, n_jobs=None):
141+
def __init__(self,
142+
ratio='auto',
143+
random_state=None,
144+
smote=None,
145+
enn=None,
146+
k=None,
147+
m=None,
148+
out_step=None,
149+
kind_smote=None,
150+
size_ngh=None,
151+
n_neighbors=None,
152+
kind_enn=None,
153+
n_jobs=None):
146154

147155
super(SMOTEENN, self).__init__(ratio=ratio, random_state=random_state)
148156
self.smote = smote
@@ -181,10 +189,14 @@ def _validate_estimator(self):
181189
warnings.warn('Parameters initialization will be replaced in'
182190
' version 0.4. Use a SMOTE object instead.',
183191
DeprecationWarning)
184-
self.smote_ = SMOTE(ratio=self.ratio,
185-
random_state=self.random_state,
186-
k=self.k, m=self.m, out_step=self.out_step,
187-
kind=self.kind_smote, n_jobs=smote_jobs)
192+
self.smote_ = SMOTE(
193+
ratio=self.ratio,
194+
random_state=self.random_state,
195+
k=self.k,
196+
m=self.m,
197+
out_step=self.out_step,
198+
kind=self.kind_smote,
199+
n_jobs=smote_jobs)
188200
# If an object was given, affect
189201
elif self.smote is not None:
190202
if isinstance(self.smote, SMOTE):
@@ -193,8 +205,8 @@ def _validate_estimator(self):
193205
raise ValueError('smote needs to be a SMOTE object.')
194206
# Otherwise create a default SMOTE
195207
else:
196-
self.smote_ = SMOTE(ratio=self.ratio,
197-
random_state=self.random_state)
208+
self.smote_ = SMOTE(
209+
ratio=self.ratio, random_state=self.random_state)
198210

199211
# Check any parameters for ENN was provided
200212
# Anounce deprecation
@@ -211,11 +223,12 @@ def _validate_estimator(self):
211223
self.kind_enn = 'all'
212224
if self.n_jobs is None:
213225
self.n_jobs = 1
214-
self.enn_ = EditedNearestNeighbours(random_state=self.random_state,
215-
size_ngh=self.size_ngh,
216-
n_neighbors=self.n_neighbors,
217-
kind_sel=self.kind_enn,
218-
n_jobs=self.n_jobs)
226+
self.enn_ = EditedNearestNeighbours(
227+
random_state=self.random_state,
228+
size_ngh=self.size_ngh,
229+
n_neighbors=self.n_neighbors,
230+
kind_sel=self.kind_enn,
231+
n_jobs=self.n_jobs)
219232
# If an object was given, affect
220233
elif self.enn is not None:
221234
if isinstance(self.enn, EditedNearestNeighbours):

imblearn/combine/smote_tomek.py

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,11 @@ class SMOTETomek(BaseBinarySampler):
9696
9797
>>> from collections import Counter
9898
>>> from sklearn.datasets import make_classification
99-
>>> from imblearn.combine import SMOTETomek
100-
>>> X, y = make_classification(n_classes=2, class_sep=2, weights=[0.1, 0.9],
101-
... n_informative=3, n_redundant=1, flip_y=0,
102-
... n_features=20, n_clusters_per_class=1,
103-
... n_samples=1000, random_state=10)
99+
>>> from imblearn.combine import \
100+
SMOTETomek # doctest: +NORMALIZE_WHITESPACE
101+
>>> X, y = make_classification(n_classes=2, class_sep=2,
102+
... weights=[0.1, 0.9], n_informative=3, n_redundant=1, flip_y=0,
103+
... n_features=20, n_clusters_per_class=1, n_samples=1000, random_state=10)
104104
>>> print('Original dataset shape {}'.format(Counter(y)))
105105
Original dataset shape Counter({1: 900, 0: 100})
106106
>>> smt = SMOTETomek(random_state=42)
@@ -115,12 +115,18 @@ class SMOTETomek(BaseBinarySampler):
115115
116116
"""
117117

118-
def __init__(self, ratio='auto', random_state=None,
119-
smote=None, tomek=None,
120-
k=None, m=None, out_step=None, kind_smote=None,
118+
def __init__(self,
119+
ratio='auto',
120+
random_state=None,
121+
smote=None,
122+
tomek=None,
123+
k=None,
124+
m=None,
125+
out_step=None,
126+
kind_smote=None,
121127
n_jobs=None):
122-
super(SMOTETomek, self).__init__(ratio=ratio,
123-
random_state=random_state)
128+
super(SMOTETomek, self).__init__(
129+
ratio=ratio, random_state=random_state)
124130
self.smote = smote
125131
self.tomek = tomek
126132
self.k = k
@@ -154,10 +160,14 @@ def _validate_estimator(self):
154160
smote_jobs = 1
155161
else:
156162
smote_jobs = self.n_jobs
157-
self.smote_ = SMOTE(ratio=self.ratio,
158-
random_state=self.random_state,
159-
k=self.k, m=self.m, out_step=self.out_step,
160-
kind=self.kind_smote, n_jobs=smote_jobs)
163+
self.smote_ = SMOTE(
164+
ratio=self.ratio,
165+
random_state=self.random_state,
166+
k=self.k,
167+
m=self.m,
168+
out_step=self.out_step,
169+
kind=self.kind_smote,
170+
n_jobs=smote_jobs)
161171
# If an object was given, affect
162172
elif self.smote is not None:
163173
if isinstance(self.smote, SMOTE):
@@ -166,17 +176,17 @@ def _validate_estimator(self):
166176
raise ValueError('smote needs to be a SMOTE object.')
167177
# Otherwise create a default SMOTE
168178
else:
169-
self.smote_ = SMOTE(ratio=self.ratio,
170-
random_state=self.random_state)
179+
self.smote_ = SMOTE(
180+
ratio=self.ratio, random_state=self.random_state)
171181

172182
# Check any parameters for ENN was provided
173183
# Anounce deprecation
174184
if self.n_jobs is not None:
175185
warnings.warn('Parameters initialization will be replaced in'
176186
' version 0.4. Use a ENN object instead.',
177187
DeprecationWarning)
178-
self.tomek_ = TomekLinks(random_state=self.random_state,
179-
n_jobs=self.n_jobs)
188+
self.tomek_ = TomekLinks(
189+
random_state=self.random_state, n_jobs=self.n_jobs)
180190
# If an object was given, affect
181191
elif self.tomek is not None:
182192
if isinstance(self.tomek, TomekLinks):

0 commit comments

Comments
 (0)