diff --git a/orangecontrib/text/__init__.py b/orangecontrib/text/__init__.py index 3a5e1bf5d..e581c9d86 100644 --- a/orangecontrib/text/__init__.py +++ b/orangecontrib/text/__init__.py @@ -1,41 +1,6 @@ # Set where NLTK data is downloaded import os -# temporary solution - remove when Orange 3.33 is released -# it must be imported before nltk_data_dir -from typing import Optional, Dict -from Orange.misc.utils import embedder_utils - - -def _get_proxies() -> Optional[Dict[str, str]]: - """ - Return dict with proxy addresses if they exist. - Returns - ------- - proxy_dict - Dictionary with format {proxy type: proxy address} or None if - they not set. - """ - def add_scheme(url: Optional[str]) -> Optional[str]: - if url is not None and "://" not in url: - # if no scheme default to http - as other libraries do (e.g. requests) - return f"http://{url}" - else: - return url - - http_proxy = add_scheme(os.environ.get("http_proxy")) - https_proxy = add_scheme(os.environ.get("https_proxy")) - proxy_dict = {} - if http_proxy: - proxy_dict["http://"] = http_proxy - if https_proxy: - proxy_dict["https://"] = https_proxy - return proxy_dict if proxy_dict else None - - -embedder_utils.get_proxies = _get_proxies -# remove to here - from orangecontrib.text.misc import nltk_data_dir os.environ['NLTK_DATA'] = nltk_data_dir() diff --git a/orangecontrib/text/tests/test_documentembedder.py b/orangecontrib/text/tests/test_documentembedder.py index 342ffccac..d65b7cfa5 100644 --- a/orangecontrib/text/tests/test_documentembedder.py +++ b/orangecontrib/text/tests/test_documentembedder.py @@ -145,16 +145,6 @@ def test_invalid_parameters(self): with self.assertRaises(ValueError): self.embedder = DocumentEmbedder(aggregator='average') - def test_remove_temporary_proxy_solution(self): - """ - When it starts to fail: - - remove this test - - remove temporary implementation of get_proxy() function in text.__inint__ - - set minimum version of Orange on 3.33 - """ - import Orange - self.assertGreater("3.34.0", Orange.__version__) - if __name__ == "__main__": unittest.main() diff --git a/orangecontrib/text/widgets/owcollocations.py b/orangecontrib/text/widgets/owcollocations.py index 3b9f81ea4..96f4b10d1 100644 --- a/orangecontrib/text/widgets/owcollocations.py +++ b/orangecontrib/text/widgets/owcollocations.py @@ -1,8 +1,8 @@ -import warnings from collections import namedtuple import numpy as np from Orange.widgets.widget import OWWidget +from Orange.widgets.gui import BarRatioTableModel from Orange.data import Domain, StringVariable, ContinuousVariable, Table from AnyQt.QtCore import Qt, pyqtSignal as Signal from AnyQt.QtWidgets import QTableView, QItemDelegate @@ -12,7 +12,6 @@ from orangecontrib.text import Corpus from orangewidget import settings, gui -from orangewidget.utils.itemmodels import PyTableModel from orangewidget.utils.signals import Input, Output from orangewidget.utils.widgetpreview import WidgetPreview @@ -73,72 +72,6 @@ def mousePressEvent(self, event): self.manualSelection.emit() -class TableModel(PyTableModel): - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - self._extremes = {} - - def data(self, index, role=Qt.DisplayRole): - if role == gui.BarRatioRole and index.isValid(): - value = super().data(index, Qt.EditRole) - if not isinstance(value, float): - return None - vmin, vmax = self._extremes.get(index.column(), (-np.inf, np.inf)) - value = (value - vmin) / ((vmax - vmin) or 1) - return value - - if role == Qt.DisplayRole and index.column() != VARNAME_COL: - role = Qt.EditRole - - value = super().data(index, role) - - # Display nothing for non-existent attr value counts in column 1 - if role == Qt.EditRole \ - and index.column() == NVAL_COL and np.isnan(value): - return '' - - return value - - def headerData(self, section, orientation, role=Qt.DisplayRole): - if role == Qt.InitialSortOrderRole: - return Qt.DescendingOrder if section > 0 else Qt.AscendingOrder - return super().headerData(section, orientation, role) - - def setExtremesFrom(self, column, values): - """Set extremes for column's ratio bars from values""" - try: - with warnings.catch_warnings(): - warnings.filterwarnings( - "ignore", ".*All-NaN slice encountered.*", RuntimeWarning) - vmin = np.nanmin(values) - if np.isnan(vmin): - raise TypeError - except TypeError: - vmin, vmax = -np.inf, np.inf - else: - vmax = np.nanmax(values) - self._extremes[column] = (vmin, vmax) - - def resetSorting(self, yes_reset=False): - # pylint: disable=arguments-differ - """We don't want to invalidate our sort proxy model everytime we - wrap a new list. Our proxymodel only invalidates explicitly - (i.e. when new data is set)""" - if yes_reset: - super().resetSorting() - - def _argsortData(self, data, order): - if data.dtype not in (float, int): - data = np.char.lower(data) - indices = np.argsort(data, kind='mergesort') - if order == Qt.DescendingOrder: - indices = indices[::-1] - if data.dtype == float: - # Always sort NaNs last - return np.roll(indices, -np.isnan(data).sum()) - return indices - - class OWCollocations(OWWidget): name = "Collocations" description = "Compute significant bigrams and trigrams." @@ -189,7 +122,8 @@ def __init__(self) -> None: autoDefault=False) # GUI - self.collModel = model = TableModel(parent=self) # type: TableModel + self.collModel = model = BarRatioTableModel(parent=self) # type: + # TableModel model.setHorizontalHeaderLabels(["Method", "Score"]) self.collView = view = TableView(self) # type: TableView self.mainArea.layout().addWidget(view) diff --git a/orangecontrib/text/widgets/tests/test_owcollocations.py b/orangecontrib/text/widgets/tests/test_owcollocations.py index 203a7d29d..b2dc65806 100644 --- a/orangecontrib/text/widgets/tests/test_owcollocations.py +++ b/orangecontrib/text/widgets/tests/test_owcollocations.py @@ -19,17 +19,6 @@ def setUp(self) -> None: # create corpus self.corpus = Corpus.from_file("deerwester") - def test_table_import_deprecated(self): - """This test will fail with Orange version > 3.32. This serves as a - reminder to port BarRatioTableModel from core Orange, remove the - redundant code in OWCollocations, and this test.""" - if LooseVersion(Orange.__version__) > LooseVersion("3.34.0"): - self.fail( - "BarRatioTableModel should now be available in the released " - "version of Orange. Please import the model from gui.py and " - "remove the redundant code." - ) - def test_set_data(self): self.send_signal(self.widget.Inputs.corpus, self.corpus) output = self.get_output(self.widget.Outputs.corpus) diff --git a/requirements.txt b/requirements.txt index e1b2a32d0..245c2a3da 100644 --- a/requirements.txt +++ b/requirements.txt @@ -10,7 +10,7 @@ lxml nltk>=3.0.5 # TweetTokenizer introduced in 3.0.5 numpy odfpy>=1.3.5 -Orange3 >=3.32.0 +Orange3 >=3.33.0 orange-widget-base >=4.14.0 orange-canvas-core owlready2 diff --git a/tox.ini b/tox.ini index 352319acc..3d3cdd82e 100644 --- a/tox.ini +++ b/tox.ini @@ -24,14 +24,16 @@ setenv = COVERAGE_FILE = {toxinidir}/.coverage COVERAGE_RCFILE = {toxinidir}/.coveragerc deps = - pyqt5==5.12.* - pyqtwebengine==5.12.* - oldest: scikit-learn~=0.23.1 - oldest: orange3==3.31.1 + pyqt5==5.12.*;platform_system=="Windows" and python_version<'3.10' + pyqt5==5.15.*;platform_system!="Windows" or python_version>='3.10' + pyqtwebengine==5.12.*;platform_system=="Windows" and python_version<'3.10' + pyqtwebengine==5.15.*;platform_system!="Windows" or python_version>='3.10' + oldest: scikit-learn==1.0.1 + oldest: orange3==3.33.0 # Use newer canvas-core and widget-base to avoid segfaults on windows - oldest: orange-canvas-core==0.1.24 - oldest: orange-widget-base==4.16.1 + oldest: orange-canvas-core==0.1.27 + oldest: orange-widget-base==4.18.0 latest: https://github.com/biolab/orange3/archive/refs/heads/master.zip#egg=orange3 latest: https://github.com/biolab/orange3-network/archive/refs/heads/master.zip#egg=orange3-network latest: https://github.com/biolab/orange-canvas-core/archive/refs/heads/master.zip#egg=orange-canvas-core