Skip to content

[FIX] Color: Fix renaming of variables #4669

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions Orange/widgets/data/owcolor.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from AnyQt.QtWidgets import QHeaderView, QColorDialog, QTableView, QComboBox

import Orange
from Orange.preprocess.transformation import Identity
from Orange.util import color_to_hex
from Orange.widgets import widget, settings, gui
from Orange.widgets.gui import HorizontalGridDelegate
Expand Down Expand Up @@ -82,7 +83,8 @@ def set_value(self, i, value):
self.new_values[i] = value

def create_variable(self):
new_var = self.var.copy(name=self.name, values=self.values)
new_var = self.var.copy(name=self.name, values=self.values,
compute_value=Identity(self.var))
new_var.colors = np.asarray(self.colors)
return new_var

Expand Down Expand Up @@ -114,7 +116,8 @@ def palette_name(self, palette_name):
self.new_palette_name = palette_name

def create_variable(self):
new_var = self.var.copy(name=self.name)
new_var = self.var.copy(name=self.name,
compute_value=Identity(self.var))
new_var.attributes["palette"] = self.palette_name
return new_var

Expand Down
10 changes: 9 additions & 1 deletion Orange/widgets/data/tests/test_owcolor.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from AnyQt.QtGui import QBrush

from Orange.data import Table, ContinuousVariable, DiscreteVariable, Domain
from Orange.preprocess.transformation import Identity
from Orange.util import color_to_hex
from Orange.widgets.utils import colorpalettes
from Orange.widgets.utils.state_summary import format_summary_details
Expand Down Expand Up @@ -58,11 +59,15 @@ def test_create_variable(self):
self.assertEqual(var.name, "z")
self.assertEqual(var.values, ("a", "d", "c"))
np.testing.assert_equal(var.colors, [[1, 2, 3], [4, 5, 6], [7, 8, 9]])
self.assertIsInstance(var.compute_value, Identity)
self.assertIs(var.compute_value.variable, desc.var)

palette = desc.var.attributes["palette"] = object()
var = desc.create_variable()
self.assertIs(desc.var.attributes["palette"], palette)
self.assertFalse(hasattr(var.attributes, "palette"))
self.assertIsInstance(var.compute_value, Identity)
self.assertIs(var.compute_value.variable, desc.var)


class ContAttrDesc(unittest.TestCase):
Expand All @@ -89,11 +94,15 @@ def test_create_variable(self):
self.assertIsInstance(var, ContinuousVariable)
self.assertEqual(var.name, "z")
self.assertEqual(var.palette.name, palette_name)
self.assertIsInstance(var.compute_value, Identity)
self.assertIs(var.compute_value.variable, desc.var)

colors = desc.var.attributes["colors"] = object()
var = desc.create_variable()
self.assertIs(desc.var.attributes["colors"], colors)
self.assertFalse(hasattr(var.attributes, "colors"))
self.assertIsInstance(var.compute_value, Identity)
self.assertIs(var.compute_value.variable, desc.var)


class BaseTestColorTableModel:
Expand Down Expand Up @@ -121,7 +130,6 @@ def test_data(self):
index = self.model.index(2, 0)
self.assertEqual(data(index, Qt.DisplayRole), self.descs[2].name)


def test_set_data(self):
emit = Mock()
try:
Expand Down