Skip to content

Commit f7090db

Browse files
committed
Select Rows: Add code for support of old settings and ensure its removal in the future
1 parent 5e4bc54 commit f7090db

File tree

2 files changed

+52
-15
lines changed

2 files changed

+52
-15
lines changed

Orange/widgets/data/owselectrows.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,12 @@ def encode_setting(self, context, setting, value):
5656
def decode_setting(self, setting, value, domain=None):
5757
value = super().decode_setting(setting, value, domain)
5858
if setting.name == 'conditions':
59-
for i, (attr, _, op, values) in enumerate(value):
59+
# Use this after 1. 1. 2021:
60+
# for i, (attr, _, op, values) in enumerate(value):
61+
for i, condition in enumerate(value):
62+
attr = condition[0]
63+
op, values = condition[-2:]
64+
6065
var = attr in domain and domain[attr]
6166
if var and var.is_continuous and not isinstance(var, TimeVariable):
6267
value[i] = (attr, op,
@@ -71,7 +76,10 @@ def match(self, context, domain, attrs, metas):
7176
conditions = context.values["conditions"]
7277
all_vars = attrs
7378
all_vars.update(metas)
74-
if all(all_vars.get(name) == tpe for name, tpe, *_ in conditions):
79+
# Use this after 1. 1. 2021:
80+
# if all(all_vars.get(name) == tpe for name, tpe, *_ in conditions):
81+
if all(all_vars.get(name) == tpe if len(rest) == 2 else name in all_vars
82+
for name, tpe, *rest in conditions):
7583
return 0.5
7684
return self.NO_MATCH
7785

@@ -705,11 +713,13 @@ def send_report(self):
705713
("Non-matching data",
706714
nonmatch_inst > 0 and "{} instances".format(nonmatch_inst))))
707715

708-
@classmethod
709-
def migrate_context(cls, context, version):
710-
if not version:
711-
# Just remove; can't migrate because variables types are unknown
712-
context.values["conditions"] = []
716+
# Uncomment this on 1. 1. 2021
717+
#
718+
# @classmethod
719+
# def migrate_context(cls, context, version):
720+
# if not version:
721+
# # Just remove; can't migrate because variables types are unknown
722+
# context.values["conditions"] = []
713723

714724

715725
class CheckBoxPopup(QWidget):

Orange/widgets/data/tests/test_owselectrows.py

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Test methods with long descriptive names can omit docstrings
22
# pylint: disable=missing-docstring
3+
import time
4+
35
from AnyQt.QtCore import QLocale, Qt
46
from AnyQt.QtTest import QTest
57
from AnyQt.QtWidgets import QLineEdit, QComboBox
@@ -259,15 +261,40 @@ def test_change_var_type(self):
259261
new_iris = iris.transform(new_domain)
260262
self.send_signal(self.widget.Inputs.data, new_iris)
261263

262-
def test_migration_to_version_1(self):
263-
iris = Table("iris")
264+
# Uncomment this on 1. 1. 2021
265+
#
266+
# def test_migration_to_version_1(self):
267+
# iris = Table("iris")
268+
#
269+
# ch = SelectRowsContextHandler()
270+
# context = ch.new_context(iris.domain, *ch.encode_domain(iris.domain))
271+
# context.values = dict(conditions=[["petal length", 2, (5.2,)]])
272+
# settings = dict(context_settings=[context])
273+
# widget = self.create_widget(OWSelectRows, settings)
274+
# self.assertEqual(widget.conditions, [])
264275

265-
ch = SelectRowsContextHandler()
266-
context = ch.new_context(iris.domain, *ch.encode_domain(iris.domain))
267-
context.values = dict(conditions=[["petal length", 2, (5.2,)]])
268-
settings = dict(context_settings=[context])
269-
widget = self.create_widget(OWSelectRows, settings)
270-
self.assertEqual(widget.conditions, [])
276+
@override_locale(QLocale.C)
277+
def test_use_settings(self):
278+
iris = Table("iris")
279+
self.widget = self.widget_with_context(
280+
iris.domain, [["sepal length", 2, ("5.2",)]])
281+
self.send_signal(self.widget.Inputs.data, iris)
282+
condition = self.widget.conditions[0]
283+
self.assertEqual(condition[0], "sepal length")
284+
self.assertEqual(condition[1], 2)
285+
self.assertTrue(condition[2][0].startswith("5.2"))
286+
287+
def test_end_support_for_version_0(self):
288+
if time.gmtime().tm_year == 2021:
289+
self.fail("""
290+
Happy new year 2021!
291+
292+
Now remove support for version==None settings in
293+
SelectRowsContextHandler.decode_setting and SelectRowsContextHandler.match,
294+
uncomment OWSelectRows.migrate, and remove this test.
295+
296+
Basically, undo this commit.
297+
""")
271298

272299
def widget_with_context(self, domain, conditions):
273300
ch = SelectRowsContextHandler()

0 commit comments

Comments
 (0)