Skip to content

Commit

Permalink
owwordcloud: Work with empty token list
Browse files Browse the repository at this point in the history
  • Loading branch information
PrimozGodec committed Oct 19, 2020
1 parent 18cc6d6 commit 7d9ab52
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
4 changes: 4 additions & 0 deletions orangecontrib/text/widgets/owwordcloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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()

0 comments on commit 7d9ab52

Please sign in to comment.