Skip to content

Commit

Permalink
Merge pull request #6531 from PrimozGodec/scatterplot-fix-wrong-features
Browse files Browse the repository at this point in the history
[FIX] Scatter Plot - Handle input features that are hidden in data
  • Loading branch information
janezd committed Sep 1, 2023
2 parents 67a7ee9 + 84eafd2 commit 972405f
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 4 deletions.
14 changes: 10 additions & 4 deletions Orange/widgets/visualize/owscatterplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,7 @@ def _point_tooltip(self, point_id, skip_attrs=()):
def can_draw_regresssion_line(self):
return self.data is not None and \
self.data.domain is not None and \
self.attr_x is not None and self.attr_y is not None and \
self.attr_x.is_continuous and \
self.attr_y.is_continuous

Expand Down Expand Up @@ -572,12 +573,13 @@ def handleNewSignals(self):
self.attr_box.setEnabled(True)
self.vizrank.setEnabled(True)
if self.attribute_selection_list and self.data is not None and \
self.data.domain is not None and \
all(attr in self.data.domain for attr
in self.attribute_selection_list):
self.attr_x, self.attr_y = self.attribute_selection_list[:2]
self.data.domain is not None:
self.attr_box.setEnabled(False)
self.vizrank.setEnabled(False)
if all(attr in self.xy_model for attr in self.attribute_selection_list):
self.attr_x, self.attr_y = self.attribute_selection_list
else:
self.attr_x, self.attr_y = None, None
self._invalidated = self._invalidated or self._xy_invalidated
self._xy_invalidated = False
super().handleNewSignals()
Expand All @@ -594,6 +596,10 @@ def set_shown_attributes(self, attributes):
or self.attr_x != attributes[0] \
or self.attr_y != attributes[1]
else:
if self.attr_x is None or self.attr_y is None:
# scenario happens when features input removed and features
# were invalid or hidden and those attr_x and attr_h were None
self.init_attr_values()
self.attribute_selection_list = None

def set_attr(self, attr_x, attr_y):
Expand Down
32 changes: 32 additions & 0 deletions Orange/widgets/visualize/tests/test_owscatterplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,38 @@ def test_features_and_data(self):
self.assertTrue(self.widget.attr_box.isEnabled())
self.assertTrue(self.widget.vizrank.isEnabled())

def test_features_and_hidden_data(self):
new_domain = self.data.domain.copy()
new_domain.attributes[0].attributes["hidden"] = True
data = self.data.transform(new_domain)

self.send_signal(self.widget.Inputs.data, data)
self.send_signal(self.widget.Inputs.features, AttributeList(data.domain[:2]))
self.assertIsNone(self.widget.attr_x)
self.assertIsNone(self.widget.attr_y)
self.assertFalse(self.widget.attr_box.isEnabled())
self.assertFalse(self.widget.vizrank.isEnabled())

self.send_signal(self.widget.Inputs.features, None)
self.assertEqual(self.widget.attr_x, self.data.domain[1])
self.assertEqual(self.widget.attr_y, self.data.domain[2])
self.assertTrue(self.widget.attr_box.isEnabled())
self.assertTrue(self.widget.vizrank.isEnabled())

# try with features not in data
bad_feat = AttributeList([ContinuousVariable("a"), ContinuousVariable("b")])
self.send_signal(self.widget.Inputs.features, bad_feat)
self.assertIsNone(self.widget.attr_x)
self.assertIsNone(self.widget.attr_y)
self.assertFalse(self.widget.attr_box.isEnabled())
self.assertFalse(self.widget.vizrank.isEnabled())

self.send_signal(self.widget.Inputs.features, None)
self.assertEqual(self.widget.attr_x, self.data.domain[1])
self.assertEqual(self.widget.attr_y, self.data.domain[2])
self.assertTrue(self.widget.attr_box.isEnabled())
self.assertTrue(self.widget.vizrank.isEnabled())

def test_output_features(self):
data = Table("iris")
self.send_signal(self.widget.Inputs.data, data)
Expand Down

0 comments on commit 972405f

Please sign in to comment.