Skip to content

Commit

Permalink
File: fix name change
Browse files Browse the repository at this point in the history
  • Loading branch information
PrimozGodec committed Nov 29, 2019
1 parent 074a238 commit 82f1032
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 3 deletions.
46 changes: 46 additions & 0 deletions Orange/widgets/data/tests/test_owfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,52 @@ def test_domain_changes_are_stored(self):
data = self.get_output(self.widget.Outputs.data)
self.assertIsInstance(data.domain["iris"], StringVariable)

def test_variable_name_change(self):
"""
Test whether the name of the variable is changed correctly by
the domaineditor.
"""
self.open_dataset("iris")

# just rename
idx = self.widget.domain_editor.model().createIndex(4, 0)
self.widget.domain_editor.model().setData(idx, "a", Qt.EditRole)
self.widget.apply_button.click()
data = self.get_output(self.widget.Outputs.data)
self.assertIn("a", data.domain)

# rename and change to text
idx = self.widget.domain_editor.model().createIndex(4, 0)
self.widget.domain_editor.model().setData(idx, "b", Qt.EditRole)
idx = self.widget.domain_editor.model().createIndex(4, 1)
self.widget.domain_editor.model().setData(idx, "text", Qt.EditRole)
self.widget.apply_button.click()
data = self.get_output(self.widget.Outputs.data)
self.assertIn("b", data.domain)
self.assertIsInstance(data.domain["b"], StringVariable)

# rename and change to discrete
idx = self.widget.domain_editor.model().createIndex(4, 0)
self.widget.domain_editor.model().setData(idx, "c", Qt.EditRole)
idx = self.widget.domain_editor.model().createIndex(4, 1)
self.widget.domain_editor.model().setData(
idx, "categorical", Qt.EditRole)
self.widget.apply_button.click()
data = self.get_output(self.widget.Outputs.data)
self.assertIn("c", data.domain)
self.assertIsInstance(data.domain["c"], DiscreteVariable)

# rename and change to continuous
self.open_dataset("zoo")
idx = self.widget.domain_editor.model().createIndex(0, 0)
self.widget.domain_editor.model().setData(idx, "c", Qt.EditRole)
idx = self.widget.domain_editor.model().createIndex(0, 1)
self.widget.domain_editor.model().setData(idx, "numeric", Qt.EditRole)
self.widget.apply_button.click()
data = self.get_output(self.widget.Outputs.data)
self.assertIn("c", data.domain)
self.assertIsInstance(data.domain["c"], ContinuousVariable)

def open_dataset(self, name):
filename = FileFormat.locate(name, dataset_dirs)
self.widget.add_path(filename)
Expand Down
4 changes: 1 addition & 3 deletions Orange/widgets/utils/domaineditor.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,9 +299,7 @@ def numbers_are_round(var, col_data):
if name == orig_var.name and tpe == type(orig_var):
var = orig_var
elif tpe == type(orig_var):
# change the name so that all_vars will get the correct name
orig_var.name = name
var = orig_var
var = orig_var.copy(name=name)
elif tpe == DiscreteVariable:
values = list(str(i) for i in unique(col_data) if not self._is_missing(i))
round_numbers = numbers_are_round(orig_var, col_data)
Expand Down

0 comments on commit 82f1032

Please sign in to comment.