Skip to content

Commit 0f8fb93

Browse files
authored
Merge pull request #2697 from jerneju/domainmodel-changeorder
[ENH] Domain Model: order without separators
2 parents c7897d2 + 3ac3052 commit 0f8fb93

2 files changed

Lines changed: 38 additions & 1 deletion

File tree

Orange/widgets/utils/itemmodels.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -869,8 +869,25 @@ class DomainModel(VariableListModel):
869869
ATTRIBUTES)
870870
PRIMITIVE = (DiscreteVariable, ContinuousVariable)
871871

872-
def __init__(self, order=SEPARATED, placeholder=None,
872+
def __init__(self, order=SEPARATED, separators=True, placeholder=None,
873873
valid_types=None, alphabetical=False, skip_hidden_vars=True, **kwargs):
874+
"""
875+
876+
Parameters
877+
----------
878+
order: tuple or int
879+
Order of attributes, metas, classes, separators and other options
880+
separators: bool
881+
If False, remove separators from `order`.
882+
placeholder: str
883+
The text that is shown when no variable is selected
884+
valid_types: tuple
885+
(Sub)types of `Variable` that are included in the model
886+
alphabetical: bool
887+
If true, variables are sorted alphabetically.
888+
skip_hidden_vars: bool
889+
If true, variables marked as "hidden" are skipped.
890+
"""
874891
super().__init__(placeholder=placeholder, **kwargs)
875892
if isinstance(order, int):
876893
order = (order,)
@@ -880,6 +897,8 @@ def __init__(self, order=SEPARATED, placeholder=None,
880897
order = (None,) + \
881898
(self.Separator, ) * (self.Separator in order) + \
882899
order
900+
if not separators:
901+
order = [e for e in order if e is not self.Separator]
883902
self.order = order
884903
self.valid_types = valid_types
885904
self.alphabetical = alphabetical

Orange/widgets/utils/tests/test_itemmodels.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,3 +310,21 @@ def test_filtering(self):
310310
skip_hidden_vars=False)
311311
model.set_domain(Domain(attrs))
312312
self.assertEqual(list(model), disc)
313+
314+
def test_no_separators(self):
315+
"""
316+
GH-2697
317+
"""
318+
attrs = [ContinuousVariable(n) for n in "abg"]
319+
classes = [ContinuousVariable(n) for n in "deh"]
320+
metas = [ContinuousVariable(n) for n in "ijf"]
321+
322+
model = DomainModel(order=DomainModel.SEPARATED, separators=False)
323+
model.set_domain(Domain(attrs, classes, metas))
324+
self.assertEqual(list(model), classes + metas + attrs)
325+
326+
model = DomainModel(order=DomainModel.SEPARATED, separators=True)
327+
model.set_domain(Domain(attrs, classes, metas))
328+
self.assertEqual(
329+
list(model),
330+
classes + [PyListModel.Separator] + metas + [PyListModel.Separator] + attrs)

0 commit comments

Comments
 (0)