diff --git a/Orange/widgets/data/owselectcolumns.py b/Orange/widgets/data/owselectcolumns.py index f511fba7747..312dad4d08a 100644 --- a/Orange/widgets/data/owselectcolumns.py +++ b/Orange/widgets/data/owselectcolumns.py @@ -362,9 +362,10 @@ def set_data(self, data=None): all_vars = data.domain.variables + data.domain.metas def attrs_for_role(role): - return [attr for _, attr in sorted( - (domain_hints[attr][1], attr) - for attr in all_vars if domain_hints[attr][0] == role)] + selected_attrs = [ + attr for attr in all_vars if domain_hints[attr][0] == role + ] + return sorted(selected_attrs, key=lambda attr: domain_hints[attr][1]) domain = data.domain domain_hints = {} diff --git a/Orange/widgets/data/tests/test_owselectcolumns.py b/Orange/widgets/data/tests/test_owselectcolumns.py index 76a1dd2d29e..5a7e87cf7bb 100644 --- a/Orange/widgets/data/tests/test_owselectcolumns.py +++ b/Orange/widgets/data/tests/test_owselectcolumns.py @@ -2,6 +2,7 @@ from unittest import TestCase from unittest.mock import Mock +import numpy as np from AnyQt.QtCore import QMimeData, QPoint, Qt from AnyQt.QtGui import QDragEnterEvent @@ -396,3 +397,17 @@ def test_summary(self): self.assertEqual(input_sum.call_args[0][0].brief, "") output_sum.assert_called_once() self.assertEqual(output_sum.call_args[0][0].brief, "") + + def test_domain_new_feature(self): + """ Test scenario when new attribute is added at position 0 """ + data = Table("iris") + self.send_signal(self.widget.Inputs.data, data) + + data1 = Table( + Domain( + (ContinuousVariable("a"),) + data.domain.attributes, + data.domain.class_var), + np.hstack((np.ones((len(data), 1)), data.X)), + data.Y + ) + self.send_signal(self.widget.Inputs.data, data1)