-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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
[ENH] Visualize widgets: Output Annotated data and Fixups #1677
Changes from all commits
1e02c01
505bee6
287407d
e4b1753
ccf1648
318e107
96031f9
8324222
dcd6f27
ae407e1
635ba39
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,37 @@ | ||
from Orange.data import Table | ||
# Test methods with long descriptive names can omit docstrings | ||
# pylint: disable=missing-docstring | ||
from Orange.widgets.data.owtable import OWDataTable | ||
from Orange.widgets.tests.base import WidgetTest | ||
from Orange.widgets.tests.base import WidgetTest, WidgetOutputsTestMixin | ||
|
||
|
||
class TestOWDataTable(WidgetTest): | ||
class TestOWDataTable(WidgetTest, WidgetOutputsTestMixin): | ||
@classmethod | ||
def setUpClass(cls): | ||
super().setUpClass() | ||
WidgetOutputsTestMixin.init(cls) | ||
|
||
cls.signal_name = "Data" | ||
cls.signal_data = cls.data | ||
|
||
def setUp(self): | ||
self.widget = self.create_widget(OWDataTable) | ||
self.iris = Table("iris") | ||
|
||
def test_input_data(self): | ||
"""Check number of tabs with data on the input""" | ||
self.send_signal("Data", self.iris, 1) | ||
self.send_signal("Data", self.data, 1) | ||
self.assertEqual(self.widget.tabs.count(), 1) | ||
self.send_signal("Data", self.iris, 2) | ||
self.send_signal("Data", self.data, 2) | ||
self.assertEqual(self.widget.tabs.count(), 2) | ||
self.send_signal("Data", None, 1) | ||
self.assertEqual(self.widget.tabs.count(), 1) | ||
|
||
def test_data_model(self): | ||
self.send_signal("Data", self.iris, 1) | ||
self.assertEqual(self.widget.tabs.widget(0).model().rowCount(), len(self.iris)) | ||
self.send_signal("Data", self.data, 1) | ||
self.assertEqual(self.widget.tabs.widget(0).model().rowCount(), | ||
len(self.data)) | ||
|
||
def _select_data(self): | ||
self.widget.selected_cols = list(range(len(self.data.domain))) | ||
self.widget.selected_rows = list(range(0, len(self.data.domain), 10)) | ||
self.widget.set_selection() | ||
return self.widget.selected_rows |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,8 +35,12 @@ | |
) | ||
|
||
from Orange.data.table import Table | ||
from Orange.widgets import gui, settings | ||
from Orange.widgets import gui, settings, widget | ||
from Orange.widgets.utils import to_html | ||
from Orange.widgets.utils.annotated_data import ( | ||
create_annotated_table, | ||
ANNOTATED_DATA_SIGNAL_NAME | ||
) | ||
from Orange.widgets.utils.colorpalette import ContinuousPaletteGenerator | ||
from Orange.widgets.visualize.pythagorastreeviewer import ( | ||
PythagorasTreeViewer, | ||
|
@@ -60,7 +64,8 @@ class OWPythagorasTree(OWWidget): | |
priority = 1000 | ||
|
||
inputs = [('Tree', TreeModel, 'set_tree')] | ||
outputs = [('Selected Data', Table)] | ||
outputs = [('Selected Data', Table, widget.Default), | ||
(ANNOTATED_DATA_SIGNAL_NAME, Table)] | ||
|
||
# Enable the save as feature | ||
graph_name = 'scene' | ||
|
@@ -228,6 +233,8 @@ def set_tree(self, model=None): | |
# if hasattr(model, 'meta_depth_limit'): | ||
# self.depth_limit = model.meta_depth_limit | ||
# self.update_depth() | ||
self.send(ANNOTATED_DATA_SIGNAL_NAME, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this needed? The "Selected data" signal is not sent here. I commented it out and it seems it still works. |
||
create_annotated_table(self.instances, None)) | ||
|
||
def clear(self): | ||
"""Clear all relevant data from the widget.""" | ||
|
@@ -343,14 +350,16 @@ def commit(self): | |
"""Commit the selected data to output.""" | ||
if self.instances is None: | ||
self.send('Selected Data', None) | ||
self.send(ANNOTATED_DATA_SIGNAL_NAME, None) | ||
return | ||
# this is taken almost directly from the owclassificationtreegraph.py | ||
items = filter(lambda x: isinstance(x, SquareGraphicsItem), | ||
self.scene.selectedItems()) | ||
|
||
nodes = [i.tree_node.label for i in self.scene.selectedItems() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Isn't this already computed above, as the second argument in the call of |
||
if isinstance(i, SquareGraphicsItem)] | ||
data = self.tree_adapter.get_instances_in_nodes( | ||
self.clf_dataset, [item.tree_node.label for item in items]) | ||
self.clf_dataset, nodes) | ||
self.send('Selected Data', data) | ||
selected_indices = self.model.get_indices(nodes) | ||
self.send(ANNOTATED_DATA_SIGNAL_NAME, | ||
create_annotated_table(self.instances, selected_indices)) | ||
|
||
def send_report(self): | ||
"""Send report.""" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to change anything here, but: you can also use set comprehensions in such cases. (I keep forgetting this, too.)