From 5f2ca7f838fba5ac0023f97153388c7d11d2912b Mon Sep 17 00:00:00 2001 From: Jernej Urankar Date: Wed, 28 Jun 2017 12:49:01 +0200 Subject: [PATCH] [FIX] Manifold Learning: handling out of memory error --- Orange/widgets/unsupervised/owmanifoldlearning.py | 3 +++ .../unsupervised/tests/test_owmanifoldlearning.py | 15 +++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/Orange/widgets/unsupervised/owmanifoldlearning.py b/Orange/widgets/unsupervised/owmanifoldlearning.py index 7c0a6247ee3..111d80b666a 100644 --- a/Orange/widgets/unsupervised/owmanifoldlearning.py +++ b/Orange/widgets/unsupervised/owmanifoldlearning.py @@ -188,6 +188,7 @@ class Error(OWWidget.Error): sparse_methods = Msg('Only t-SNE method supported on sparse data') sparse_tsne_distance = Msg('Chebyshev, Jaccard, and Mahalanobis ' 'distances not supported with sparse data.') + out_of_memory = Msg("Out of memory") def __init__(self): self.data = None @@ -271,6 +272,8 @@ def apply(self): self.Error.n_neighbors_too_small("{}".format(n)) else: self.Error.manifold_error(e.args[0]) + except MemoryError: + self.Error.out_of_memory() except np.linalg.linalg.LinAlgError as e: self.Error.manifold_error(str(e)) self.Outputs.transformed_data.send(out) diff --git a/Orange/widgets/unsupervised/tests/test_owmanifoldlearning.py b/Orange/widgets/unsupervised/tests/test_owmanifoldlearning.py index 944c40717df..7578637a357 100644 --- a/Orange/widgets/unsupervised/tests/test_owmanifoldlearning.py +++ b/Orange/widgets/unsupervised/tests/test_owmanifoldlearning.py @@ -1,5 +1,7 @@ # Test methods with long descriptive names can omit docstrings # pylint: disable=missing-docstring +from unittest.mock import patch, Mock + import numpy as np from scipy import sparse @@ -108,3 +110,16 @@ def test_singular_matrices(self): self.assertFalse(self.widget.Error.manifold_error.is_shown()) self.widget.apply_button.button.click() self.assertTrue(self.widget.Error.manifold_error.is_shown()) + + def test_out_of_memory(self): + """ + Show error message when out of memory. + GH-2441 + """ + table = Table("iris") + with patch("Orange.projection.manifold.MDS.__call__", Mock()) as mock: + mock.side_effect = MemoryError + self.send_signal("Data", table) + self.widget.manifold_methods_combo.activated.emit(1) + self.widget.apply_button.button.click() + self.assertTrue(self.widget.Error.out_of_memory.is_shown())