Skip to content

Commit

Permalink
Test & Learn: handling memory error
Browse files Browse the repository at this point in the history
  • Loading branch information
jerneju committed May 23, 2017
1 parent e7e0a70 commit de1d842
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
13 changes: 9 additions & 4 deletions Orange/widgets/evaluate/owtestlearners.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = \
Expand Down Expand Up @@ -648,19 +649,23 @@ 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])
combined.learner_names = [learner_name(slot.learner)
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)

Expand Down
15 changes: 15 additions & 0 deletions Orange/widgets/evaluate/tests/test_owtestlearners.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit de1d842

Please sign in to comment.