From d2059a5e03388f4d6fb7db696f51abdeef04f81c Mon Sep 17 00:00:00 2001 From: Marko Toplak Date: Fri, 10 May 2024 14:45:07 +0200 Subject: [PATCH] Monkey-patch scipy.linalg.triu for gensim --- orangecontrib/text/corpus.py | 8 ++++++++ orangecontrib/text/tests/test_corpus.py | 12 ++++++++++++ 2 files changed, 20 insertions(+) diff --git a/orangecontrib/text/corpus.py b/orangecontrib/text/corpus.py index f4c80577c..b0660a830 100644 --- a/orangecontrib/text/corpus.py +++ b/orangecontrib/text/corpus.py @@ -19,6 +19,14 @@ ) from Orange.preprocess.transformation import Identity from Orange.data.util import get_unique_names + +# Gensim is 4.3.2 is incompatible with scipy 1.3, where they removed triu/ +# thus hack what it is missing here it. +# Remove this section after we depend on newer gensim +import scipy.linalg +if "triu" not in scipy.linalg.__dict__: + scipy.linalg.triu = np.triu + from gensim import corpora from orangewidget.utils.signals import summarize, PartialSummary import scipy.sparse as sp diff --git a/orangecontrib/text/tests/test_corpus.py b/orangecontrib/text/tests/test_corpus.py index 42a82df92..aa20b5f4f 100644 --- a/orangecontrib/text/tests/test_corpus.py +++ b/orangecontrib/text/tests/test_corpus.py @@ -27,6 +27,18 @@ from orangecontrib.text.tag import AveragedPerceptronTagger +class ImportHack(unittest.TestCase): + + def test_perhaps_remove_gensim_hack(self): + now = datetime.now() + if (now.year, now.month) >= (2024, 7): + self.fail( + "Check if gensim newer than 4.3.2 is available; if so, add it " + "to requirements, remove the scipy monkey-patch in corpus.py " + "and this test." + ) + + class CorpusTests(unittest.TestCase): def setUp(self): self.pos_tagger = AveragedPerceptronTagger()