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] Select Columns: Fix attributes sorting #4827

Merged
merged 1 commit into from
May 28, 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: 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)