Skip to content

Commit c3e7011

Browse files
authored
Merge pull request #5822 from PrimozGodec/remove-odl-verisons-support
Remove old settings support in Select Rows
2 parents 82c8827 + 172b33d commit c3e7011

File tree

2 files changed

+31
-106
lines changed

2 files changed

+31
-106
lines changed

Orange/widgets/data/owselectrows.py

Lines changed: 21 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from AnyQt.QtWidgets import (
88
QWidget, QTableWidget, QHeaderView, QComboBox, QLineEdit, QToolButton,
99
QMessageBox, QMenu, QListView, QGridLayout, QPushButton, QSizePolicy,
10-
QLabel, QHBoxLayout, QDateTimeEdit)
10+
QLabel, QDateTimeEdit)
1111
from AnyQt.QtGui import (QDoubleValidator, QStandardItemModel, QStandardItem,
1212
QFontMetrics, QPalette)
1313
from AnyQt.QtCore import Qt, QPoint, QPersistentModelIndex, QLocale, \
@@ -74,31 +74,19 @@ def decode_setting(self, setting, value, domain=None, *_args):
7474
value = super().decode_setting(setting, value, domain)
7575
if setting.name == 'conditions':
7676
CONTINUOUS = vartype(ContinuousVariable("x"))
77-
# Use this after 2022/2/2:
78-
# for i, (attr, tpe, op, values) in enumerate(value):
79-
# if tpe is not None:
80-
for i, (attr, *tpe, op, values) in enumerate(value):
81-
if tpe != [None] \
82-
or not tpe and attr not in OWSelectRows.AllTypes:
77+
for i, (attr, tpe, op, values) in enumerate(value):
78+
if tpe is not None:
8379
attr = domain[attr]
8480
# check for exact match, pylint: disable=unidiomatic-typecheck
8581
if type(attr) is ContinuousVariable \
8682
or OWSelectRows.AllTypes.get(attr) == CONTINUOUS:
8783
values = [QLocale().toString(float(i), 'f') for i in values]
8884
elif isinstance(attr, DiscreteVariable):
89-
# After 2022/2/2, use just the expression in else clause
90-
if values and isinstance(values[0], int):
91-
# Backwards compatibility. Reset setting if we detect
92-
# that the number of values decreased. Still broken if
93-
# they're reordered or we don't detect the decrease.
94-
#
95-
# indices start with 1, thus >, not >=
96-
if max(values) > len(attr.values):
97-
values = (0, )
98-
else:
99-
values = tuple(attr.to_val(val) + 1 if val else 0
100-
for val in values if val in attr.values) \
101-
or (0, )
85+
values = tuple(
86+
attr.to_val(val) + 1 if val else 0
87+
for val in values
88+
if val in attr.values
89+
) or (0,)
10290
value[i] = (attr, op, values)
10391
return value
10492

@@ -109,10 +97,10 @@ def match(self, context, domain, attrs, metas):
10997
conditions = context.values["conditions"]
11098
all_vars = attrs.copy()
11199
all_vars.update(metas)
112-
matched = [all_vars.get(name) == tpe # also matches "all (...)" strings
113-
# After 2022/2/2 remove this line:
114-
if len(rest) == 2 else name in all_vars
115-
for name, tpe, *rest in conditions]
100+
matched = [
101+
all_vars.get(name) == tpe # also matches "all (...)" strings
102+
for name, tpe, *rest in conditions
103+
]
116104
if any(matched):
117105
return 0.5 * sum(matched) / len(matched)
118106
return self.NO_MATCH
@@ -125,15 +113,11 @@ def filter_value(self, setting, data, domain, attrs, metas):
125113
all_vars = attrs.copy()
126114
all_vars.update(metas)
127115
conditions = data["conditions"]
128-
# Use this after 2022/2/2: if any(all_vars.get(name) == tpe:
129-
# conditions[:] = [(name, tpe, *rest) for name, tpe, *rest in conditions
130-
# if all_vars.get(name) == tpe]
131116
conditions[:] = [
132-
(name, tpe, *rest) for name, tpe, *rest in conditions
133-
# all_vars.get(name) == tpe also matches "all (...)" which are
134-
# encoded with type `None`
135-
if (all_vars.get(name) == tpe if len(rest) == 2
136-
else name in all_vars)]
117+
(name, tpe, *rest)
118+
for name, tpe, *rest in conditions
119+
if all_vars.get(name) == tpe
120+
]
137121

138122

139123
class FilterDiscreteType(enum.Enum):
@@ -779,13 +763,11 @@ def send_report(self):
779763
("Non-matching data",
780764
nonmatch_inst > 0 and "{} instances".format(nonmatch_inst))))
781765

782-
# Uncomment this on 2022/2/2
783-
#
784-
# @classmethod
785-
# def migrate_context(cls, context, version):
786-
# if not version or version < 2:
787-
# # Just remove; can't migrate because variables types are unknown
788-
# context.values["conditions"] = []
766+
@classmethod
767+
def migrate_context(cls, context, version):
768+
if not version or version < 2:
769+
# Just remove; can't migrate because variables types are unknown
770+
context.values["conditions"] = []
789771

790772

791773
class CheckBoxPopup(QWidget):

Orange/widgets/data/tests/test_owselectrows.py

Lines changed: 10 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -310,37 +310,6 @@ def test_partial_match_values(self):
310310
self.assertEqual(condition[1], 2)
311311
self.assertEqual(condition[2], (2, )) # index of value + 1
312312

313-
def test_backward_compat_match_values(self):
314-
iris = Table("iris")
315-
domain = iris.domain
316-
class_var = domain.class_var
317-
self.widget = self.widget_with_context(
318-
domain, [[class_var.name, 1, 2, (1, 2)]])
319-
320-
new_class_var = DiscreteVariable(class_var.name, class_var.values[1:])
321-
new_domain = Domain(domain.attributes, new_class_var)
322-
non0 = iris.Y != 0
323-
iris2 = Table.from_numpy(new_domain, iris.X[non0], iris.Y[non0] - 1)
324-
self.send_signal(self.widget.Inputs.data, iris2)
325-
condition = self.widget.conditions[0]
326-
self.assertIs(condition[0], new_class_var)
327-
self.assertEqual(condition[1], 2)
328-
self.assertEqual(condition[2], (1, 2)) # index of value + 1
329-
330-
# reset to [0] if out of range
331-
self.widget = self.widget_with_context(
332-
domain, [[class_var.name, 1, 2, (1, 3)]])
333-
334-
new_class_var = DiscreteVariable(class_var.name, class_var.values[1:])
335-
new_domain = Domain(domain.attributes, new_class_var)
336-
non0 = iris.Y != 0
337-
iris2 = Table.from_numpy(new_domain, iris.X[non0], iris.Y[non0] - 1)
338-
self.send_signal(self.widget.Inputs.data, iris2)
339-
condition = self.widget.conditions[0]
340-
self.assertIs(condition[0], new_class_var)
341-
self.assertEqual(condition[1], 2)
342-
self.assertEqual(condition[2], (0, )) # index of value + 1
343-
344313
@override_locale(QLocale.C)
345314
def test_partial_matches_with_missing_vars(self):
346315
iris = Table("iris")
@@ -532,43 +501,15 @@ def test_report(self, _):
532501
self.enterFilter(zoo.domain[1], "is one of")
533502
self.widget.send_report() # don't crash
534503

535-
# Uncomment this on 2022/2/2
536-
#
537-
# def test_migration_to_version_1(self):
538-
# iris = Table("iris")
539-
#
540-
# ch = SelectRowsContextHandler()
541-
# context = ch.new_context(iris.domain, *ch.encode_domain(iris.domain))
542-
# context.values = dict(conditions=[["petal length", 2, (5.2,)]])
543-
# settings = dict(context_settings=[context])
544-
# widget = self.create_widget(OWSelectRows, settings)
545-
# self.assertEqual(widget.conditions, [])
546-
547-
@override_locale(QLocale.C)
548-
def test_support_old_settings(self):
504+
def test_migration_to_version_1(self):
549505
iris = Table("iris")
550-
self.widget = self.widget_with_context(
551-
iris.domain, [["sepal length", 2, ("5.2",)]])
552-
self.send_signal(self.widget.Inputs.data, iris)
553-
condition = self.widget.conditions[0]
554-
self.assertEqual(condition[0], iris.domain["sepal length"])
555-
self.assertEqual(condition[1], 2)
556-
self.assertTrue(condition[2][0].startswith("5.2"))
557-
558-
def test_end_support_for_version_1(self):
559-
if time.gmtime() >= (2022, 2, 2):
560-
self.fail("""
561-
Happy 22/2/2!
562-
563-
Now remove support for version==None settings in
564-
SelectRowsContextHandler.decode_setting and SelectRowsContextHandler.match,
565-
and uncomment OWSelectRows.migrate.
566-
567-
In tests, uncomment test_migration_to_version_1,
568-
and remove test_support_old_settings and this test.
569506

570-
Basically, revert this commit.
571-
""")
507+
ch = SelectRowsContextHandler()
508+
context = ch.new_context(iris.domain, *ch.encode_domain(iris.domain))
509+
context.values = dict(conditions=[["petal length", 2, (5.2,)]])
510+
settings = dict(context_settings=[context])
511+
widget = self.create_widget(OWSelectRows, settings)
512+
self.assertEqual(widget.conditions, [])
572513

573514
def test_purge_discretized(self):
574515
housing = Table("housing")
@@ -577,7 +518,9 @@ def test_purge_discretized(self):
577518
discretize_class=True, method=method)
578519
domain = discretizer(housing)
579520
data = housing.transform(domain)
580-
widget = self.widget_with_context(domain, [["MEDV", 101, 2, (2, 3)]])
521+
widget = self.widget_with_context(
522+
domain, [["MEDV", 101, 2, domain.class_var.values[1:]]]
523+
)
581524
widget.purge_classes = True
582525
self.send_signal(widget.Inputs.data, data)
583526
out = self.get_output(widget.Outputs.matching_data)

0 commit comments

Comments
 (0)