Skip to content
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

[FIX] File widget: fix name change #4235

Merged
merged 1 commit into from
Nov 29, 2019
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
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