Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] Resolve deprecations #63

Merged
merged 5 commits into from
Aug 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion orangecontrib/explain/explainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,7 @@ def get_instance_ordering(
NotImplementedError if unknown order_by.
"""
if isinstance(order_by, Variable):
x_data = data.get_column_view(order_by)[0]
x_data = data.get_column(order_by)
clust_ord = np.argsort(hclust_ordering(shap_values))
return np.lexsort([clust_ord, x_data])
elif order_by == ORIGINAL_ORDER:
Expand Down
2 changes: 1 addition & 1 deletion orangecontrib/explain/tests/test_explainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ def test_all_regressors(self):
if learner == CurveFitLearner:
attr = self.housing.domain.attributes
learner = CurveFitLearner(
lambda x, a: np.sum(x[:, i] for i in range(len(attr))),
lambda x, a: sum(x[:, i] for i in range(len(attr))),
[], [a.name for a in self.housing.domain.attributes]
)
else:
Expand Down
5 changes: 3 additions & 2 deletions orangecontrib/explain/widgets/owexplainfeaturebase.py
Original file line number Diff line number Diff line change
Expand Up @@ -549,16 +549,17 @@ def _update_plot(self):
def _clear_selection(self):
if self.selection:
self.selection = ()
self.commit()
self.commit.deferred()

def update_selection(self, *_):
raise NotImplementedError

def select_pending(self, pending_selection: Tuple):
self.__pending_selection = pending_selection
self.unconditional_commit()
self.commit.now()

# Outputs
@gui.deferred
def commit(self):
selected_data = self.get_selected_data()
if not selected_data:
Expand Down
2 changes: 1 addition & 1 deletion orangecontrib/explain/widgets/owexplainmodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ def update_selection(self, min_val: float, max_val: float, attr_name: str):
if not self.selection and not any(mask):
return
self.selection = (attr_name, list(np.flatnonzero(mask)))
self.commit()
self.commit.deferred()

def select_pending(self, pending_selection: Tuple):
if not pending_selection or not pending_selection[1] \
Expand Down
9 changes: 5 additions & 4 deletions orangecontrib/explain/widgets/owexplainpredictions.py
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,7 @@ def _add_plot(self):

def __on_selection_changed(self, selection: List[Tuple[float, float]]):
self.selection_ranges = selection
self.commit()
self.commit.deferred()

def _add_controls(self):
box = gui.vBox(self.controlArea, "Target class")
Expand Down Expand Up @@ -624,12 +624,12 @@ def _add_controls(self):
def __on_target_changed(self):
self.selection_ranges = []
self.setup_plot()
self.commit()
self.commit.deferred()

def __on_order_changed(self):
self.selection_ranges = []
self.setup_plot()
self.commit()
self.commit.deferred()

def __on_annot_changed(self):
if not self.__results or not self.data:
Expand Down Expand Up @@ -717,7 +717,7 @@ def _setup_controls(self):
def handleNewSignals(self):
self.clear()
self.start(run, self.data, self.background_data, self.model)
self.commit()
self.commit.deferred()

def clear(self):
self.__results = None
Expand Down Expand Up @@ -815,6 +815,7 @@ def apply_selection(self):
self.__on_selection_changed(selection_ranges)
self.__pending_selection = []

@gui.deferred
def commit(self):
selected = None
selected_indices = []
Expand Down
25 changes: 11 additions & 14 deletions orangecontrib/explain/widgets/owice.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@

import numpy as np
from AnyQt.QtCore import Qt, QSortFilterProxyModel, QSize, QModelIndex, \
QItemSelection, QPointF, Signal, QLineF
QPointF, Signal, QLineF
from AnyQt.QtGui import QColor
from AnyQt.QtWidgets import QComboBox, QSizePolicy, QGraphicsSceneHelpEvent, \
QToolTip, QGraphicsLineItem, QApplication

import pyqtgraph as pg

from orangecanvas.gui.utils import disconnected
from orangewidget.utils.listview import ListViewSearch
from orangewidget.utils.listview import ListViewFilter

from Orange.base import Model
from Orange.data import Table, ContinuousVariable, Variable, \
Expand Down Expand Up @@ -261,7 +261,7 @@ def __on_mouse_moved(self, point: QPointF):
)

# points
x_data = self.__data.get_column_view(self.__feature)[0][indices]
x_data = self.__data.get_column(self.__feature)[indices]
n_dec = self.__feature.number_of_decimals
y_data = []
for i, x in zip(indices, x_data):
Expand Down Expand Up @@ -537,7 +537,7 @@ def __init__(self):
self.domain: Optional[Domain] = None
self.graph: ICEPlot = None
self._target_combo: QComboBox = None
self._features_view: ListViewSearch = None
self._features_view: ListViewFilter = None
self._features_model: VariableListModel = None
self._color_model: DomainModel = None

Expand Down Expand Up @@ -571,10 +571,10 @@ def _add_controls(self):
box = gui.vBox(self.controlArea, "Feature")
self._features_model = VariableListModel()
sorted_model = SortProxyModel(sortRole=Qt.UserRole)
sorted_model.setSourceModel(self._features_model)
sorted_model.sort(0)
self._features_view = ListViewSearch()
self._features_view.setModel(sorted_model)
self._features_view = ListViewFilter(
model=self._features_model, proxy=sorted_model
)
self._features_view.setMinimumSize(QSize(30, 100))
self._features_view.setSizePolicy(QSizePolicy.Expanding,
QSizePolicy.Expanding)
Expand All @@ -600,12 +600,9 @@ def __on_target_changed(self):
self._apply_feature_sorting()
self.__on_parameter_changed()

def __on_feature_changed(self, selection: QItemSelection):
if not selection:
return

self.feature = selection.indexes()[0].data(gui.TableVariable)
self._apply_feature_sorting()
def __on_feature_changed(self):
selection = self._features_view.selectionModel().selectedIndexes()
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sometimes while filtering, __on_feature_changed is called two times. First with a selection change and second without change (both selected and deselected parameters are empty). Since it is safer, use self._features_view.selectionModel().selectedIndexes().

self.feature = selection[0].data(gui.TableVariable) if selection else None
self._run()

def __on_order_changed(self):
Expand Down Expand Up @@ -788,7 +785,7 @@ def setup_plot(self):
color_labels = None
if self.color_var and self.color_var.is_discrete:
colors = self.color_var.colors
color_col = self.data[mask].get_column_view(self.color_var)[0]
color_col = self.data[mask].get_column(self.color_var)
color_labels = self.color_var.values

self.graph.set_data(self.data[mask], self.feature,
Expand Down
2 changes: 1 addition & 1 deletion orangecontrib/explain/widgets/owpermutationimportance.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ def update_selection(self, attr_names: Set[str]):
return
assert self.results is not None
self.selection = tuple(attr_names)
self.commit()
self.commit.deferred()

def select_pending(self, pending_selection: Tuple):
if not pending_selection or self.results is None:
Expand Down
17 changes: 11 additions & 6 deletions orangecontrib/explain/widgets/tests/test_owice.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
# pylint: disable=missing-docstring
import unittest
from unittest.mock import Mock
from unittest.mock import Mock, patch

from AnyQt.QtCore import Qt, QPointF

from Orange.classification import RandomForestLearner, CalibratedLearner, \
ThresholdLearner, SimpleRandomForestLearner as SimpleRandomForestClassifier
from Orange.data import Table
from Orange.data.table import DomainTransformationError
from Orange.regression import RandomForestRegressionLearner, \
SimpleRandomForestLearner
from Orange.tests.test_classification import all_learners as all_cls_learners
Expand Down Expand Up @@ -39,15 +40,19 @@ def test_input_cls(self):

self.send_signal(self.widget.Inputs.model, self.rf_reg)
self.wait_until_finished()
self.assertTrue(self.widget.Error.unknown_err.is_shown())
# no error since no attributes in view and those no future is selected
self.assertFalse(self.widget.Error.unknown_err.is_shown())
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The model and data domain are different, which results in no attributes in the list view and those no feature is selected. ICE shows an empty graph without error.


self.send_signal(self.widget.Inputs.model, None)
self.assertFalse(self.widget.Error.unknown_err.is_shown())

self.send_signal(self.widget.Inputs.data, self.iris)
self.send_signal(self.widget.Inputs.model, self.rf_cls)
self.wait_until_finished()
self.assertTrue(self.widget.Error.domain_transform_err.is_shown())
with patch(
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I cannot make a case where DomainTransformationError is raised. When a new domain doesn't have attributes from the model, the list view is empty, resulting in an empty feature variable and the process finishing with None (before domain transformation).

I hope I didn't miss any cases. I would anyway leave domain_transform_err, so I added a test with a patch for it.

"orangecontrib.explain.widgets.owice.individual_condition_expectation",
side_effect=DomainTransformationError
):
self.send_signal(self.widget.Inputs.model, self.rf_cls)
self.wait_until_finished()
self.assertTrue(self.widget.Error.domain_transform_err.is_shown())

def test_output(self):
self.send_signal(self.widget.Inputs.data, self.heart)
Expand Down
6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@
INSTALL_REQUIRES = [
"AnyQt",
"numpy",
"Orange3 >= 3.33.0",
"orange-widget-base",
"orange-canvas-core",
"Orange3 >=3.34.0",
"orange-canvas-core >=0.1.28",
"orange-widget-base >=4.19.0",
"pyqtgraph",
"scipy",
"shap >=0.42.1",
Expand Down
6 changes: 3 additions & 3 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ deps =
{env:WEBENGINE_PYPI_NAME:PyQtWebEngine}=={env:WEBENGINE_PYPI_VERSION:5.15.*}
xgboost
oldest: scikit-learn==1.0.1
oldest: orange3==3.33.0
oldest: orange-canvas-core==0.1.27
oldest: orange-widget-base==4.18.0
oldest: orange3==3.34.0
oldest: orange-canvas-core==0.1.28
oldest: orange-widget-base==4.19.0
latest: https://github.com/biolab/orange3/archive/refs/heads/master.zip#egg=orange3
latest: https://github.com/biolab/orange-canvas-core/archive/refs/heads/master.zip#egg=orange-canvas-core
latest: https://github.com/biolab/orange-widget-base/archive/refs/heads/master.zip#egg=orange-widget-base
Expand Down