Skip to content

Commit

Permalink
[FIX] Feature Constructor: no fail when no values
Browse files Browse the repository at this point in the history
  • Loading branch information
jerneju committed Jun 21, 2017
1 parent 0d075f0 commit fe02689
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Orange/widgets/data/owfeatureconstructor.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ def setEditorData(self, data, domain):
def editorData(self):
values = self.valuesedit.text()
values = re.split(r"(?<!\\),", values)
values = tuple(v.replace(r"\,", ",").strip() for v in values)
values = tuple(filter(None, [v.replace(r"\,", ",").strip() for v in values]))
return DiscreteDescriptor(
name=self.nameedit.text(),
values=values,
Expand Down
22 changes: 21 additions & 1 deletion Orange/widgets/data/tests/test_owfeatureconstructor.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
from Orange.widgets.data.owfeatureconstructor import (DiscreteDescriptor,
ContinuousDescriptor,
StringDescriptor,
construct_variables, OWFeatureConstructor)
construct_variables, OWFeatureConstructor,
DiscreteFeatureEditor)

from Orange.widgets.data.owfeatureconstructor import freevars, validate_exp

Expand Down Expand Up @@ -238,3 +239,22 @@ def test_error_invalid_expression(self):
)
self.widget.apply()
self.assertTrue(self.widget.Error.invalid_expressions.is_shown())

def test_discrete_no_values(self):
"""
Should not fail when there are no values set.
GH-2417
"""
data = Table("iris")
self.widget.setData(data)
discreteFeatureEditor = DiscreteFeatureEditor()

discreteFeatureEditor.valuesedit.setText("")
discreteFeatureEditor.nameedit.setText("D1")
discreteFeatureEditor.expressionedit.setText("iris")
self.widget.addFeature(
discreteFeatureEditor.editorData()
)
self.assertFalse(self.widget.Error.more_values_needed.is_shown())
self.widget.apply()
self.assertTrue(self.widget.Error.more_values_needed.is_shown())

0 comments on commit fe02689

Please sign in to comment.