Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] Test & Learn: handling memory error #2316

Merged
merged 1 commit into from
May 25, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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