Skip to content

Commit eca8c46

Browse files
committed
projections: Remove 'Preprocessor' output
1 parent 4f68700 commit eca8c46

File tree

7 files changed

+5
-90
lines changed

7 files changed

+5
-90
lines changed

Orange/preprocess/preprocess.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -536,18 +536,6 @@ def transform(var):
536536
return data.transform(domain)
537537

538538

539-
class ApplyDomain(Preprocess):
540-
def __init__(self, domain, name):
541-
self._domain = domain
542-
self._name = name
543-
544-
def __call__(self, data):
545-
return data.transform(self._domain)
546-
547-
def __str__(self):
548-
return self._name
549-
550-
551539
class PreprocessorList(Preprocess):
552540
"""
553541
Store a list of preprocessors and on call apply them to the dataset.

Orange/widgets/tests/base.py

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
)
3232
from Orange.modelling import Fitter
3333
from Orange.preprocess import RemoveNaNColumns, Randomize, Continuize
34-
from Orange.preprocess.preprocess import PreprocessorList, Preprocess
34+
from Orange.preprocess.preprocess import PreprocessorList
3535
from Orange.regression.base_regression import (
3636
LearnerRegression, ModelRegression
3737
)
@@ -1074,18 +1074,6 @@ def test_manual_move(self):
10741074
self.assertEqual(len(self.widget.graph.scatterplot_item.data), nvalid)
10751075
np.testing.assert_equal(self.widget.graph.selection, selection)
10761076

1077-
def test_output_preprocessor(self):
1078-
self.send_signal(self.widget.Inputs.data, self.data)
1079-
pp = self.get_output(self.widget.Outputs.preprocessor)
1080-
self.assertIsInstance(pp, Preprocess)
1081-
transformed = pp(self.data[::10])
1082-
self.assertIsInstance(transformed, Table)
1083-
self.assertEqual(transformed.X.shape, (len(self.data) / 10, 2))
1084-
output = self.get_output(self.widget.Outputs.annotated_data)
1085-
np.testing.assert_array_equal(transformed.X, output.metas[::10, :2])
1086-
self.assertEqual([a.name for a in transformed.domain.attributes],
1087-
[m.name for m in output.domain.metas[:2]])
1088-
10891077

10901078
class datasets:
10911079
@staticmethod

Orange/widgets/unsupervised/owpca.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ class Outputs:
4040
transformed_data = Output("Transformed data", Table)
4141
components = Output("Components", Table)
4242
pca = Output("PCA", PCA, dynamic=False)
43-
preprocessor = Output("Preprocessor", preprocess.Preprocess)
4443

4544
settingsHandler = settings.DomainContextHandler()
4645

@@ -265,7 +264,6 @@ def clear_outputs(self):
265264
self.Outputs.transformed_data.send(None)
266265
self.Outputs.components.send(None)
267266
self.Outputs.pca.send(self._pca_projector)
268-
self.Outputs.preprocessor.send(None)
269267

270268
def get_model(self):
271269
if self.rpca is None:
@@ -426,7 +424,7 @@ def _update_axis(self):
426424
axis.setTicks([[(i, str(i+1)) for i in range(0, p, d)]])
427425

428426
def commit(self):
429-
transformed = components = pp = None
427+
transformed = components = None
430428
if self._pca is not None:
431429
if self._transformed is None:
432430
# Compute the full transform (MAX_COMPONENTS components) only once.
@@ -450,13 +448,10 @@ def commit(self):
450448
metas=metas)
451449
components.name = 'components'
452450

453-
pp = preprocess.ApplyDomain(domain, "PCA")
454-
455451
self._pca_projector.component = self.ncomponents
456452
self.Outputs.transformed_data.send(transformed)
457453
self.Outputs.components.send(components)
458454
self.Outputs.pca.send(self._pca_projector)
459-
self.Outputs.preprocessor.send(pp)
460455

461456
def send_report(self):
462457
if self.data is None:

Orange/widgets/unsupervised/owtsne.py

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from Orange.widgets.utils.widgetpreview import WidgetPreview
1515
from Orange.widgets.visualize.owscatterplotgraph import OWScatterPlotBase
1616
from Orange.widgets.visualize.utils.widget import OWDataProjectionWidget
17-
from Orange.widgets.widget import Msg, Output
17+
from Orange.widgets.widget import Msg
1818

1919

2020
class TSNERunner:
@@ -86,9 +86,6 @@ class OWtSNE(OWDataProjectionWidget):
8686
#: Runtime state
8787
Running, Finished, Waiting, Paused = 1, 2, 3, 4
8888

89-
class Outputs(OWDataProjectionWidget.Outputs):
90-
preprocessor = Output("Preprocessor", preprocess.Preprocess)
91-
9289
class Error(OWDataProjectionWidget.Error):
9390
not_enough_rows = Msg("Input data needs at least 2 rows")
9491
constant_data = Msg("Input data is constant")
@@ -370,10 +367,6 @@ def setup_plot(self):
370367
super().setup_plot()
371368
self.start()
372369

373-
def commit(self):
374-
super().commit()
375-
self.send_preprocessor()
376-
377370
def _get_projection_data(self):
378371
if self.data is None:
379372
return None
@@ -389,12 +382,6 @@ def _get_projection_data(self):
389382
self.data.domain.metas + self.projection.domain.attributes)
390383
return data
391384

392-
def send_preprocessor(self):
393-
prep = None
394-
if self.data is not None and self.projection is not None:
395-
prep = preprocess.ApplyDomain(self.projection.domain, self.projection.name)
396-
self.Outputs.preprocessor.send(prep)
397-
398385
def clear(self):
399386
super().clear()
400387
self.__state = OWtSNE.Waiting

Orange/widgets/unsupervised/tests/test_owpca.py

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
from Orange.data import Table, Domain, ContinuousVariable, TimeVariable
88
from Orange.preprocess import preprocess
9-
from Orange.preprocess.preprocess import Preprocess, Normalize
9+
from Orange.preprocess.preprocess import Normalize
1010
from Orange.widgets.tests.base import WidgetTest
1111
from Orange.widgets.tests.utils import table_dense_sparse
1212
from Orange.widgets.unsupervised.owpca import OWPCA
@@ -202,15 +202,3 @@ def test_do_not_mask_features(self):
202202
self.widget.set_data(data)
203203
ndata = Table("iris.tab")
204204
self.assertEqual(data.domain[0], ndata.domain[0])
205-
206-
def test_output_preprocessor(self):
207-
self.send_signal(self.widget.Inputs.data, self.iris)
208-
pp = self.get_output(self.widget.Outputs.preprocessor)
209-
self.assertIsInstance(pp, Preprocess)
210-
transformed_data = pp(self.iris[::10])
211-
self.assertIsInstance(transformed_data, Table)
212-
self.assertEqual(transformed_data.X.shape, (15, 2))
213-
output = self.get_output(self.widget.Outputs.transformed_data)
214-
np.testing.assert_array_equal(transformed_data.X, output.X[::10])
215-
self.assertEqual([a.name for a in transformed_data.domain.attributes],
216-
[m.name for m in output.domain.attributes])

Orange/widgets/unsupervised/tests/test_owtsne.py

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import numpy as np
44

55
from Orange.data import DiscreteVariable, ContinuousVariable, Domain, Table
6-
from Orange.preprocess import Preprocess, Normalize
6+
from Orange.preprocess import Normalize
77
from Orange.projection.manifold import TSNE
88
from Orange.widgets.tests.base import (
99
WidgetTest, WidgetOutputsTestMixin, ProjectionWidgetTestMixin
@@ -111,28 +111,6 @@ def test_attr_models(self):
111111
self.assertNotIn(var, controls.attr_size.model())
112112
self.assertIn(var, controls.attr_shape.model())
113113

114-
def test_output_preprocessor(self):
115-
# To test the validity of the preprocessor, we'll have to actually
116-
# compute the projections
117-
self.restore_mocked_functions()
118-
119-
self.send_signal(self.widget.Inputs.data, self.data)
120-
self.wait_until_stop_blocking(wait=20000)
121-
output_data = self.get_output(self.widget.Outputs.annotated_data)
122-
123-
# We send the same data to the widget, we expect the point locations to
124-
# be fairly close to their original ones
125-
pp = self.get_output(self.widget.Outputs.preprocessor)
126-
self.assertIsInstance(pp, Preprocess)
127-
128-
transformed_data = pp(self.data)
129-
self.assertIsInstance(transformed_data, Table)
130-
self.assertEqual(transformed_data.X.shape, (len(self.data), 2))
131-
np.testing.assert_allclose(transformed_data.X, output_data.metas[:, :2],
132-
rtol=1, atol=3)
133-
self.assertEqual([a.name for a in transformed_data.domain.attributes],
134-
[m.name for m in output_data.domain.metas[:2]])
135-
136114
def test_multiscale_changed(self):
137115
self.assertFalse(self.widget.controls.multiscale.isChecked())
138116
self.assertTrue(self.widget.perplexity_spin.isEnabled())

Orange/widgets/visualize/utils/widget.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
)
1111
from Orange.data.util import get_unique_names, array_equal
1212
from Orange.data.sql.table import SqlTable
13-
from Orange.preprocess.preprocess import Preprocess, ApplyDomain
1413
from Orange.statistics.util import bincount
1514

1615
from Orange.widgets import gui, report
@@ -624,7 +623,6 @@ class OWAnchorProjectionWidget(OWDataProjectionWidget):
624623

625624
class Outputs(OWDataProjectionWidget.Outputs):
626625
components = Output("Components", Table)
627-
preprocessor = Output("Preprocessor", Preprocess)
628626

629627
class Error(OWDataProjectionWidget.Error):
630628
sparse_data = Msg("Sparse data is not supported")
@@ -702,7 +700,6 @@ def _get_projection_data(self):
702700
def commit(self):
703701
super().commit()
704702
self.send_components()
705-
self.send_preprocessor()
706703

707704
def send_components(self):
708705
components = None
@@ -721,12 +718,6 @@ def _send_components_metas(self):
721718
variable_names = [a.name for a in self.projection.domain.attributes]
722719
return np.array(variable_names, dtype=object)[:, None]
723720

724-
def send_preprocessor(self):
725-
prep = None
726-
if self.data is not None and self.projection is not None:
727-
prep = ApplyDomain(self.projection.domain, self.projection.name)
728-
self.Outputs.preprocessor.send(prep)
729-
730721
def clear(self):
731722
super().clear()
732723
self.projector = self.projection = None

0 commit comments

Comments
 (0)