From 7d9ab52823a0b88ecf6bcbd5205b971b8fa2474b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Primo=C5=BE=20Godec?= Date: Mon, 19 Oct 2020 12:58:54 +0200 Subject: [PATCH] owwordcloud: Work with empty token list --- orangecontrib/text/widgets/owwordcloud.py | 4 ++++ .../{test_owworldcloud.py => test_owwordcloud.py} | 11 ++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) rename orangecontrib/text/widgets/tests/{test_owworldcloud.py => test_owwordcloud.py} (95%) diff --git a/orangecontrib/text/widgets/owwordcloud.py b/orangecontrib/text/widgets/owwordcloud.py index d0cbade07..f58183771 100644 --- a/orangecontrib/text/widgets/owwordcloud.py +++ b/orangecontrib/text/widgets/owwordcloud.py @@ -331,6 +331,10 @@ def _repopulate_wordcloud( weights Words' weights """ + if not len(words): + self.clear() + return + def is_whole(d): """Whether or not d is a whole number.""" return ( diff --git a/orangecontrib/text/widgets/tests/test_owworldcloud.py b/orangecontrib/text/widgets/tests/test_owwordcloud.py similarity index 95% rename from orangecontrib/text/widgets/tests/test_owworldcloud.py rename to orangecontrib/text/widgets/tests/test_owwordcloud.py index 26df5c5b0..c185109ad 100644 --- a/orangecontrib/text/widgets/tests/test_owworldcloud.py +++ b/orangecontrib/text/widgets/tests/test_owwordcloud.py @@ -17,7 +17,7 @@ pkg_resources.get_distribution("orange3").version < "3.24.0", "Wait until finished not implemented in lower version" ) -class TestWorldCloudWidget(WidgetTest): +class TestWordCloudWidget(WidgetTest): def setUp(self): self.widget = self.create_widget(OWWordCloud) self.corpus = Corpus.from_file('deerwester') @@ -203,6 +203,15 @@ def test_send_report(self): self.wait_until_finished() self.widget.send_report() + def test_no_tokens(self): + """ + In some very rare cases (when all text strings empty) word cloud all + token lists empty. Widget must work in those cases. + """ + self.corpus.metas = np.array([[" "]] * len(self.corpus)) + self.send_signal(self.widget.Inputs.corpus, self.corpus) + self.wait_until_finished() + if __name__ == "__main__": unittest.main()