Skip to content

Commit 981317c

Browse files
committed
PCA - Make lint happier
1 parent 7f92b3f commit 981317c

File tree

2 files changed

+19
-19
lines changed

2 files changed

+19
-19
lines changed

Orange/widgets/unsupervised/owpca.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from AnyQt.QtCore import Qt
66

77
from orangewidget.report import bool_str
8+
from orangewidget.settings import Setting
89

910
from Orange.data import Table, Domain, StringVariable, ContinuousVariable
1011
from Orange.data.util import get_unique_names
@@ -39,12 +40,12 @@ class Outputs:
3940
components = Output("Components", Table)
4041
pca = Output("PCA", PCA, dynamic=False)
4142

42-
ncomponents = settings.Setting(2)
43-
variance_covered = settings.Setting(100)
44-
auto_commit = settings.Setting(True)
45-
normalize = settings.Setting(True)
46-
maxp = settings.Setting(20)
47-
axis_labels = settings.Setting(10)
43+
ncomponents = Setting(2)
44+
variance_covered = Setting(100)
45+
auto_commit = Setting(True)
46+
normalize = Setting(True)
47+
maxp = Setting(20)
48+
axis_labels = Setting(10)
4849

4950
graph_name = "plot.plotItem" # QGraphicsView (pg.PlotWidget -> SliderGraph)
5051

@@ -223,8 +224,7 @@ def _setup_plot(self):
223224
self._update_axis()
224225

225226
def _on_cut_changed(self, components):
226-
if components == self.ncomponents \
227-
or self.ncomponents == 0:
227+
if self.ncomponents in (components, 0):
228228
return
229229

230230
self.ncomponents = components
@@ -334,9 +334,9 @@ def commit(self):
334334
proposed = [a.name for a in self._pca.orig_domain.attributes]
335335
meta_name = get_unique_names(proposed, 'components')
336336
meta_vars = [StringVariable(name=meta_name)]
337-
metas = numpy.array([['PC{}'.format(i + 1)
338-
for i in range(self.ncomponents)]],
339-
dtype=object).T
337+
metas = numpy.array(
338+
[[f"PC{i + 1}"for i in range(self.ncomponents)]], dtype=object
339+
).T
340340
if self._variance_ratio is not None:
341341
variance_name = get_unique_names(proposed, "variance")
342342
meta_vars.append(ContinuousVariable(variance_name))
@@ -366,7 +366,7 @@ def send_report(self):
366366
self.report_items((
367367
("Normalize data", bool_str(self.normalize)),
368368
("Selected components", self.ncomponents),
369-
("Explained variance", "{:.3f} %".format(self.variance_covered))
369+
("Explained variance", f"{self.variance_covered:.3f} %")
370370
))
371371
self.report_plot()
372372

Orange/widgets/unsupervised/tests/test_owpca.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44
from unittest.mock import patch, Mock
55

66
import numpy as np
7+
from sklearn.utils import check_random_state
8+
from sklearn.utils.extmath import svd_flip
79

810
from Orange.data import Table, Domain, ContinuousVariable, TimeVariable
911
from Orange.preprocess import preprocess
1012
from Orange.widgets.tests.base import WidgetTest
1113
from Orange.widgets.tests.utils import table_dense_sparse, possible_duplicate_table
1214
from Orange.widgets.unsupervised.owpca import OWPCA
1315
from Orange.tests import test_filename
14-
from sklearn.utils import check_random_state
15-
from sklearn.utils.extmath import svd_flip
1616

1717

1818
class TestOWPCA(WidgetTest):
@@ -63,19 +63,19 @@ def test_limit_components(self):
6363
self.widget._setup_plot() # pylint: disable=protected-access
6464

6565
def test_migrate_settings_limits_components(self):
66-
settings = dict(ncomponents=10)
66+
settings = {"ncomponents": 10}
6767
OWPCA.migrate_settings(settings, 0)
6868
self.assertEqual(settings['ncomponents'], 10)
69-
settings = dict(ncomponents=101)
69+
settings = {"ncomponents": 101}
7070
OWPCA.migrate_settings(settings, 0)
7171
self.assertEqual(settings['ncomponents'], 100)
7272

7373
def test_migrate_settings_changes_variance_covered_to_int(self):
74-
settings = dict(variance_covered=17.5)
74+
settings = {"variance_covered": 17.5}
7575
OWPCA.migrate_settings(settings, 0)
7676
self.assertEqual(settings["variance_covered"], 17)
7777

78-
settings = dict(variance_covered=float('nan'))
78+
settings = {"variance_covered": float('nan')}
7979
OWPCA.migrate_settings(settings, 0)
8080
self.assertEqual(settings["variance_covered"], 100)
8181

@@ -282,7 +282,7 @@ def test_table_subclass(self):
282282
When input table is instance of Table's subclass (e.g. Corpus) resulting
283283
tables should also be an instance subclasses
284284
"""
285-
class TableSub(Table):
285+
class TableSub(Table): # pylint: disable=abstract-method
286286
pass
287287

288288
table_subclass = TableSub(self.iris)

0 commit comments

Comments
 (0)