Skip to content

Commit

Permalink
Merge pull request #2397 from jerneju/memory-rules
Browse files Browse the repository at this point in the history
[FIX] CN2 Rule Induction: handling memory error
  • Loading branch information
janezd authored Jul 21, 2017
2 parents f48682b + ea5620d commit 6f27ecb
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
16 changes: 10 additions & 6 deletions Orange/widgets/model/owrules.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,13 +322,17 @@ def update_model(self):
"""
Reimplemented from OWBaseLearner.
"""
self.Error.out_of_memory.clear()
self.model = None
if self.check_data():
self.model = self.learner(self.data)
self.model.name = self.learner_name
self.model.instances = self.data
self.valid_data = True
else:
self.model = None
try:
self.model = self.learner(self.data)
except MemoryError:
self.Error.out_of_memory()
else:
self.model.name = self.learner_name
self.model.instances = self.data
self.valid_data = True
self.send(self.OUTPUT_MODEL_NAME, self.model)

def create_learner(self):
Expand Down
17 changes: 17 additions & 0 deletions Orange/widgets/model/tests/test_owrulesclassification.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Test methods with long descriptive names can omit docstrings
# pylint: disable=missing-docstring
import unittest

from scipy import sparse

from AnyQt.QtWidgets import (
Expand Down Expand Up @@ -116,3 +118,18 @@ def test_sparse_data(self):
self.send_signal("Data", None)
self.widget.apply_button.button.click()
self.assertFalse(self.widget.Error.sparse_not_supported.is_shown())

def test_out_of_memory(self):
"""
Handling memory error.
GH-2397
"""
data = Table("iris")[::3]
self.assertFalse(self.widget.Error.out_of_memory.is_shown())
with unittest.mock.patch(
"Orange.widgets.model.owrules.CustomRuleLearner.__call__",
side_effect=MemoryError):
self.send_signal("Data", data)
self.assertTrue(self.widget.Error.out_of_memory.is_shown())
self.send_signal("Data", None)
self.assertFalse(self.widget.Error.out_of_memory.is_shown())
1 change: 1 addition & 0 deletions Orange/widgets/utils/owlearnerwidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ class Error(OWWidget.Error):
data_error = Msg("{}")
fitting_failed = Msg("Fitting failed.\n{}")
sparse_not_supported = Msg("Sparse data is not supported.")
out_of_memory = Msg("Out of memory.")

class Warning(OWWidget.Warning):
outdated_learner = Msg("Press Apply to submit changes.")
Expand Down

0 comments on commit 6f27ecb

Please sign in to comment.