diff --git a/Orange/widgets/evaluate/owtestlearners.py b/Orange/widgets/evaluate/owtestlearners.py index 3619b627dbb..112fea6b2b0 100644 --- a/Orange/widgets/evaluate/owtestlearners.py +++ b/Orange/widgets/evaluate/owtestlearners.py @@ -217,6 +217,7 @@ class Error(OWWidget.Error): too_many_folds = Msg("Number of folds exceeds the data size") class_inconsistent = Msg("Test and train data sets " "have different target variables.") + memory_error = Msg("Not enough memory.") class Warning(OWWidget.Warning): missing_data = \ @@ -648,8 +649,11 @@ def commit(self): """ Commit the results to output. """ + self.Error.memory_error.clear() valid = [slot for slot in self.learners.values() if slot.results is not None and slot.results.success] + combined = None + predictions = None if valid: # Evaluation results combined = results_merge([slot.results.value for slot in valid]) @@ -657,10 +661,11 @@ def commit(self): for slot in valid] # Predictions & Probabilities - predictions = combined.get_augmented_data(combined.learner_names) - else: - combined = None - predictions = None + try: + predictions = combined.get_augmented_data(combined.learner_names) + except MemoryError: + self.Error.memory_error() + self.Outputs.evaluations_results.send(combined) self.Outputs.predictions.send(predictions) diff --git a/Orange/widgets/evaluate/tests/test_owtestlearners.py b/Orange/widgets/evaluate/tests/test_owtestlearners.py index ff5ac2722e4..af559ce1a4a 100644 --- a/Orange/widgets/evaluate/tests/test_owtestlearners.py +++ b/Orange/widgets/evaluate/tests/test_owtestlearners.py @@ -141,6 +141,21 @@ def test_migrate_removes_invalid_contexts(self): self.widget.migrate_settings(settings, 2) self.assertEqual(settings['context_settings'], [context_valid]) + def test_memory_error(self): + """ + Handling memory error. + GH-2316 + """ + data = Table("iris")[::3] + self.send_signal("Data", data) + self.assertFalse(self.widget.Error.memory_error.is_shown()) + + with unittest.mock.patch( + "Orange.evaluation.testing.Results.get_augmented_data", + side_effect=MemoryError): + self.send_signal("Learner", MajorityLearner(), 0, wait=5000) + self.assertTrue(self.widget.Error.memory_error.is_shown()) + class TestHelpers(unittest.TestCase): def test_results_one_vs_rest(self):