Skip to content

Commit

Permalink
Merge pull request #4827 from PrimozGodec/fix-select-columns
Browse files Browse the repository at this point in the history
[FIX] Select Columns: Fix attributes sorting
  • Loading branch information
lanzagar authored May 28, 2020
2 parents 5cd99c7 + f6b7dde commit f1ea981
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
7 changes: 4 additions & 3 deletions Orange/widgets/data/owselectcolumns.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
Expand Down
15 changes: 15 additions & 0 deletions Orange/widgets/data/tests/test_owselectcolumns.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)

0 comments on commit f1ea981

Please sign in to comment.