diff --git a/Orange/widgets/data/owfeatureconstructor.py b/Orange/widgets/data/owfeatureconstructor.py index cadb56b6bbe..03dae6c5e3e 100644 --- a/Orange/widgets/data/owfeatureconstructor.py +++ b/Orange/widgets/data/owfeatureconstructor.py @@ -244,7 +244,7 @@ def setEditorData(self, data, domain): def editorData(self): values = self.valuesedit.text() values = re.split(r"(?= (3, 0): return ast.arg(arg=name, annotation=None) else: - return ast.Name(id=arg, ctx=ast.Param(), lineno=1, col_offset=0) + return ast.Name(id=name, ctx=ast.Param(), lineno=1, col_offset=0) lambda_ = ast.Lambda( args=ast.arguments( @@ -902,7 +902,7 @@ def make_arg(name): "weibullvariate": random.weibullvariate, "triangular": random.triangular, "uniform": random.uniform} -) + ) class FeatureFunc: @@ -930,8 +930,10 @@ def unique(seq): return unique_el -def main(argv=sys.argv): +def main(argv=None): from AnyQt.QtWidgets import QApplication + if argv is None: + argv = sys.argv app = QApplication(list(argv)) argv = app.arguments() if len(argv) > 1: diff --git a/Orange/widgets/data/tests/test_owfeatureconstructor.py b/Orange/widgets/data/tests/test_owfeatureconstructor.py index 992322abd0a..fbb164181bb 100644 --- a/Orange/widgets/data/tests/test_owfeatureconstructor.py +++ b/Orange/widgets/data/tests/test_owfeatureconstructor.py @@ -11,11 +11,10 @@ from Orange.widgets.data.owfeatureconstructor import (DiscreteDescriptor, ContinuousDescriptor, StringDescriptor, - construct_variables, OWFeatureConstructor) + construct_variables, OWFeatureConstructor, + DiscreteFeatureEditor) -from Orange.widgets.data.owfeatureconstructor import ( - freevars, make_lambda, validate_exp -) +from Orange.widgets.data.owfeatureconstructor import freevars, validate_exp import dill as pickle # Import dill after Orange because patched @@ -99,11 +98,11 @@ class PicklingTest(unittest.TestCase): def test_lambdas_pickle(self): NONLOCAL_CONST = 5 - lambda_func = lambda x, LOCAL_CONST=7: \ - x * LOCAL_CONST * NONLOCAL_CONST * self.CLASS_CONST * GLOBAL_CONST + lambda_func = lambda x, local_const=7: \ + x * local_const * NONLOCAL_CONST * self.CLASS_CONST * GLOBAL_CONST - def nested_func(x, LOCAL_CONST=7): - return x * LOCAL_CONST * NONLOCAL_CONST * self.CLASS_CONST * GLOBAL_CONST + def nested_func(x, local_const=7): + return x * local_const * NONLOCAL_CONST * self.CLASS_CONST * GLOBAL_CONST self.assertEqual(lambda_func(11), pickle.loads(pickle.dumps(lambda_func))(11)) @@ -240,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())