Skip to content

Commit 6546931

Browse files
committed
SelectRows: Fix loading of conditions
1 parent 7ad7488 commit 6546931

File tree

2 files changed

+35
-5
lines changed

2 files changed

+35
-5
lines changed

Orange/widgets/data/owselectrows.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -194,9 +194,7 @@ def add_row(self, attr=None, condition_type=None, condition_value=None):
194194
minimumContentsLength=12,
195195
sizeAdjustPolicy=QComboBox.AdjustToMinimumContentsLengthWithIcon)
196196
attr_combo.row = row
197-
for var in filter_visible(chain(self.data.domain.class_vars,
198-
self.data.domain.metas,
199-
self.data.domain.attributes)):
197+
for var in self._visible_variables(self.data.domain):
200198
attr_combo.addItem(*gui.attributeItem(var))
201199
attr_combo.setCurrentIndex(attr or 0)
202200
self.cond_list.setCellWidget(row, 0, attr_combo)
@@ -216,6 +214,13 @@ def add_row(self, attr=None, condition_type=None, condition_value=None):
216214

217215
self.cond_list.resizeRowToContents(row)
218216

217+
@staticmethod
218+
def _visible_variables(domain):
219+
"""Generate variables in order they should be presented in in combos."""
220+
return filter_visible(chain(domain.class_vars,
221+
domain.metas,
222+
domain.attributes))
223+
219224
def add_all(self):
220225
if self.cond_list.rowCount():
221226
Mb = QMessageBox
@@ -395,8 +400,7 @@ def set_data(self, data):
395400
except Exception:
396401
pass
397402

398-
variables = list(filter_visible(chain(data.domain.variables,
399-
data.domain.metas)))
403+
variables = list(self._visible_variables(self.data.domain))
400404
varnames = [v.name for v in variables]
401405
if self.conditions:
402406
for attr, cond_type, cond_value in self.conditions:

Orange/widgets/data/tests/test_owselectrows.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,32 @@ def test_restores_continuous_filter_in_sl_SI_locale(self):
190190
values = self.widget.conditions[0][2]
191191
self.assertTrue(values[0].startswith("5,2"))
192192

193+
def test_load_settings(self):
194+
iris = Table("iris")[:5]
195+
self.send_signal("Data", iris)
196+
197+
sepal_length, sepal_width = iris.domain[:2]
198+
199+
# Validating with C locale should accept decimal point
200+
self.widget.remove_all_button.click()
201+
self.enterFilter(sepal_width, "is below", "5.2")
202+
self.enterFilter(sepal_length, "is at most", "4")
203+
data = self.widget.settingsHandler.pack_data(self.widget)
204+
205+
w2 = self.create_widget(OWSelectRows, data)
206+
self.send_signal("Data", iris, widget=w2)
207+
208+
var_combo = w2.cond_list.cellWidget(0, 0)
209+
self.assertEquals(var_combo.currentText(), "sepal width")
210+
oper_combo = w2.cond_list.cellWidget(0, 1)
211+
self.assertEquals(oper_combo.currentText(), "is below")
212+
213+
var_combo = w2.cond_list.cellWidget(1, 0)
214+
self.assertEquals(var_combo.currentText(), "sepal length")
215+
oper_combo = w2.cond_list.cellWidget(1, 1)
216+
self.assertEquals(oper_combo.currentText(), "is at most")
217+
218+
193219
def widget_with_context(self, domain, conditions):
194220
ch = SelectRowsContextHandler()
195221
context = ch.new_context(domain, *ch.encode_domain(domain))

0 commit comments

Comments
 (0)