Skip to content

Commit

Permalink
Revert "Owpca: rename new vars if necessary"
Browse files Browse the repository at this point in the history
This reverts commit 53299b8.
  • Loading branch information
AndrejaKovacic committed May 16, 2020
1 parent 120ed37 commit 46c571b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 27 deletions.
23 changes: 3 additions & 20 deletions Orange/widgets/unsupervised/owpca.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import numbers
from itertools import chain

import numpy
from AnyQt.QtWidgets import QFormLayout
from AnyQt.QtCore import Qt

from Orange.data import Table, Domain, StringVariable, ContinuousVariable
from Orange.data.sql.table import SqlTable, AUTO_DL_LIMIT
from Orange.data.util import get_unique_names
from Orange.preprocess import preprocess
from Orange.projection import PCA
from Orange.widgets import widget, gui, settings
Expand Down Expand Up @@ -292,33 +290,18 @@ def commit(self):
# Compute the full transform (MAX_COMPONENTS components) once.
self._transformed = self._pca(self.data)
transformed = self._transformed
d = self.data.domain

names = [var.name for var in chain(d.attributes, d.class_vars, d.metas) if var]
proposed = [var.name for var in transformed.domain.attributes[:self.ncomponents]]
unique = get_unique_names(names, proposed)

transformed_attributes = []
for var, u in zip(transformed.domain.attributes[:self.ncomponents], unique):
if var.name != u:
transformed_attributes.append(var.copy(u))
else:
transformed_attributes.append(var)

domain = Domain(
transformed_attributes,
transformed.domain.attributes[:self.ncomponents],
self.data.domain.class_vars,
self.data.domain.metas
)
transformed = transformed.from_table(domain, transformed)
# prevent caching new features by defining compute_value
comp_names = [a.name for a in self._pca.orig_domain.attributes]
meta_var = get_unique_names(comp_names, 'component')

dom = Domain(
[ContinuousVariable(a.name, compute_value=lambda _: None)
for a in self._pca.orig_domain.attributes],
metas=[StringVariable(name=meta_var)])
metas=[StringVariable(name='component')])
metas = numpy.array([['PC{}'.format(i + 1)
for i in range(self.ncomponents)]],
dtype=object).T
Expand All @@ -329,7 +312,7 @@ def commit(self):
data_dom = Domain(
self.data.domain.attributes,
self.data.domain.class_vars,
self.data.domain.metas + tuple(transformed_attributes))
self.data.domain.metas + domain.attributes)
data = Table.from_numpy(
data_dom, self.data.X, self.data.Y,
numpy.hstack((self.data.metas, transformed.X)))
Expand Down
8 changes: 1 addition & 7 deletions Orange/widgets/unsupervised/tests/test_owpca.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from Orange.preprocess import preprocess
from Orange.preprocess.preprocess import Normalize
from Orange.widgets.tests.base import WidgetTest
from Orange.widgets.tests.utils import table_dense_sparse, possible_duplicate_table
from Orange.widgets.tests.utils import table_dense_sparse
from Orange.widgets.unsupervised.owpca import OWPCA
from Orange.tests import test_filename
from sklearn.utils import check_random_state
Expand All @@ -26,12 +26,6 @@ def test_set_variance100(self):
self.widget.variance_covered = 100
self.widget._update_selection_variance_spin()

def test_renaming_of_vars(self):
data = possible_duplicate_table('component')
self.widget.set_data(data)
out = self.get_output(self.widget.Outputs.components)
self.assertEqual(out.domain.metas[0].name, 'component (1)')

def test_constant_data(self):
data = self.iris[::5]
data.X[:, :] = 1.0
Expand Down

0 comments on commit 46c571b

Please sign in to comment.