Skip to content

Commit

Permalink
[MRG+1] Fix alerts found with lgtm (scikit-learn#9278)
Browse files Browse the repository at this point in the history
* compare values rather than references

* add __ne__ to class

* add missing self parameter

* properly initialise child class using super()

* remove useless loop variables and assigments

* remove useless return statements

* respect PEP8 style

* fix another flake8 check
  • Loading branch information
jhelie authored and dmohns committed Aug 7, 2017
1 parent 41b2695 commit c43743e
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 36 deletions.
12 changes: 4 additions & 8 deletions benchmarks/bench_plot_nmf.py
Expand Up @@ -203,15 +203,11 @@ class _PGNMF(NMF):
def __init__(self, n_components=None, solver='pg', init=None,
tol=1e-4, max_iter=200, random_state=None,
alpha=0., l1_ratio=0., nls_max_iter=10):
super(_PGNMF, self).__init__(
n_components=n_components, init=init, solver=solver, tol=tol,
max_iter=max_iter, random_state=random_state, alpha=alpha,
l1_ratio=l1_ratio)
self.nls_max_iter = nls_max_iter
self.n_components = n_components
self.init = init
self.solver = solver
self.tol = tol
self.max_iter = max_iter
self.random_state = random_state
self.alpha = alpha
self.l1_ratio = l1_ratio

def fit(self, X, y=None, **params):
self.fit_transform(X, **params)
Expand Down
4 changes: 2 additions & 2 deletions benchmarks/bench_plot_randomized_svd.py
Expand Up @@ -182,7 +182,7 @@ def plot_time_vs_s(time, norm, point_labels, title):
plt.figure()
colors = ['g', 'b', 'y']
for i, l in enumerate(sorted(norm.keys())):
if l is not "fbpca":
if l != "fbpca":
plt.plot(time[l], norm[l], label=l, marker='o', c=colors.pop())
else:
plt.plot(time[l], norm[l], label=l, marker='^', c='red')
Expand All @@ -200,7 +200,7 @@ def scatter_time_vs_s(time, norm, point_labels, title):
plt.figure()
size = 100
for i, l in enumerate(sorted(norm.keys())):
if l is not "fbpca":
if l != "fbpca":
plt.scatter(time[l], norm[l], label=l, marker='o', c='b', s=size)
for label, x, y in zip(point_labels, list(time[l]), list(norm[l])):
plt.annotate(label, xy=(x, y), xytext=(0, -80),
Expand Down
15 changes: 4 additions & 11 deletions sklearn/covariance/graph_lasso_.py
Expand Up @@ -324,15 +324,13 @@ class GraphLasso(EmpiricalCovariance):

def __init__(self, alpha=.01, mode='cd', tol=1e-4, enet_tol=1e-4,
max_iter=100, verbose=False, assume_centered=False):
super(GraphLasso, self).__init__(assume_centered=assume_centered)
self.alpha = alpha
self.mode = mode
self.tol = tol
self.enet_tol = enet_tol
self.max_iter = max_iter
self.verbose = verbose
self.assume_centered = assume_centered
# The base class needs this for the score method
self.store_precision = True

def fit(self, X, y=None):

Expand Down Expand Up @@ -551,18 +549,13 @@ class GraphLassoCV(GraphLasso):
def __init__(self, alphas=4, n_refinements=4, cv=None, tol=1e-4,
enet_tol=1e-4, max_iter=100, mode='cd', n_jobs=1,
verbose=False, assume_centered=False):
super(GraphLassoCV, self).__init__(
mode=mode, tol=tol, verbose=verbose, enet_tol=enet_tol,
max_iter=max_iter, assume_centered=assume_centered)
self.alphas = alphas
self.n_refinements = n_refinements
self.mode = mode
self.tol = tol
self.enet_tol = enet_tol
self.max_iter = max_iter
self.verbose = verbose
self.cv = cv
self.n_jobs = n_jobs
self.assume_centered = assume_centered
# The base class needs this for the score method
self.store_precision = True

@property
@deprecated("Attribute grid_scores was deprecated in version 0.19 and "
Expand Down
12 changes: 4 additions & 8 deletions sklearn/decomposition/sparse_pca.py
Expand Up @@ -257,18 +257,14 @@ class MiniBatchSparsePCA(SparsePCA):
def __init__(self, n_components=None, alpha=1, ridge_alpha=0.01,
n_iter=100, callback=None, batch_size=3, verbose=False,
shuffle=True, n_jobs=1, method='lars', random_state=None):

self.n_components = n_components
self.alpha = alpha
self.ridge_alpha = ridge_alpha
super(MiniBatchSparsePCA, self).__init__(
n_components=n_components, alpha=alpha, verbose=verbose,
ridge_alpha=ridge_alpha, n_jobs=n_jobs, method=method,
random_state=random_state)
self.n_iter = n_iter
self.callback = callback
self.batch_size = batch_size
self.verbose = verbose
self.shuffle = shuffle
self.n_jobs = n_jobs
self.method = method
self.random_state = random_state

def fit(self, X, y=None):
"""Fit the model from data in X.
Expand Down
2 changes: 1 addition & 1 deletion sklearn/mixture/gaussian_mixture.py
Expand Up @@ -91,7 +91,7 @@ def _check_precision_matrix(precision, covariance_type):

def _check_precisions_full(precisions, covariance_type):
"""Check the precision matrices are symmetric and positive-definite."""
for k, prec in enumerate(precisions):
for prec in precisions:
_check_precision_matrix(prec, covariance_type)


Expand Down
2 changes: 1 addition & 1 deletion sklearn/random_projection.py
Expand Up @@ -309,7 +309,7 @@ def __init__(self, n_components='auto', eps=0.1, dense_output=False,
self.random_state = random_state

@abstractmethod
def _make_random_matrix(n_components, n_features):
def _make_random_matrix(self, n_components, n_features):
""" Generate the random projection matrix
Parameters
Expand Down
2 changes: 1 addition & 1 deletion sklearn/tree/export.py
Expand Up @@ -66,7 +66,7 @@ def _color_brew(n):


class Sentinel(object):
def __repr__():
def __repr__(self):
return '"tree.dot"'
SENTINEL = Sentinel()

Expand Down
3 changes: 3 additions & 0 deletions sklearn/utils/mocking.py
Expand Up @@ -36,6 +36,9 @@ def __array__(self, dtype=None):
def __eq__(self, other):
return MockDataFrame(self.array == other.array)

def __ne__(self, other):
return not self == other


class CheckingClassifier(BaseEstimator, ClassifierMixin):
"""Dummy classifier to test pipelining and meta-estimators.
Expand Down
8 changes: 4 additions & 4 deletions sklearn/utils/sparsefuncs.py
Expand Up @@ -302,9 +302,9 @@ def inplace_swap_row(X, m, n):
Index of the row of X to be swapped.
"""
if isinstance(X, sp.csc_matrix):
return inplace_swap_row_csc(X, m, n)
inplace_swap_row_csc(X, m, n)
elif isinstance(X, sp.csr_matrix):
return inplace_swap_row_csr(X, m, n)
inplace_swap_row_csr(X, m, n)
else:
_raise_typeerror(X)

Expand All @@ -329,9 +329,9 @@ def inplace_swap_column(X, m, n):
if n < 0:
n += X.shape[1]
if isinstance(X, sp.csc_matrix):
return inplace_swap_row_csr(X, m, n)
inplace_swap_row_csr(X, m, n)
elif isinstance(X, sp.csr_matrix):
return inplace_swap_row_csc(X, m, n)
inplace_swap_row_csc(X, m, n)
else:
_raise_typeerror(X)

Expand Down

0 comments on commit c43743e

Please sign in to comment.