[FIX] OWSom: Fix crash for data without class variable#6763
[FIX] OWSom: Fix crash for data without class variable#6763janezd merged 4 commits intobiolab:masterfrom
Conversation
|
|
Orange/widgets/unsupervised/owsom.py
Outdated
|
|
||
| if not self.data.domain.class_vars: | ||
| class_vars, metas = grp_var, som_attrs | ||
| self.data.domain.class_vars = () |
There was a problem hiding this comment.
Please remove the above. We consider Domain immutable, so class_vars must not be changed, neither is there any need to change them because that already equal ().
| def test_make_domain_without_class_vars(self): | ||
| widget = self.widget | ||
| self.send_signal(self.widget.Inputs.data, self.iris) | ||
| widget.data.domain.class_vars = None |
There was a problem hiding this comment.
You must not do this. widget.data is a data table, and widget.data.domain describes its columns. By removing classes, the table and its domain are inconsistent, and anything can happen. (Also. domain is internally inconsistent because when class_var is not None, class_vars equals (class_var, ).)
Instead, you must construct a new domain and convert the table.
data = self.iris.transform(Domain(self.iris.domain.attributes))
self.send_signal(self.widget.Inputs.data, data)
The first line creates a new data table without class, and the second line sends it to the widget. Then you can remove widget.update_output().
| self.send_signal(self.widget.Inputs.data, self.iris) | ||
| widget.data.domain.class_vars = None | ||
| widget.update_output() | ||
| self.assertIsNotNone(self.get_output(widget.Outputs.annotated_data)) |
There was a problem hiding this comment.
This doesn't test much. You may want to test two things. First, if you want to test that the widget no longer crashes, this line is unnecessary -- it would crash in the previous line (prior to your fix). But a better test would be that the widget constructs a correct domain. The proper test is
def test_make_domain_without_class_vars(self):
widget = self.widget
data = self.iris.transform(Domain(self.iris.domain.attributes))
self.send_signal(self.widget.Inputs.data, data)
domain = self.get_output((widget.Outputs.annotated_data)).domain
self.assertEqual(domain.attributes, data.domain.attributes)
self.assertEqual(domain.class_var.name, ANNOTATED_DATA_FEATURE_NAME)
self.assertEqual([var.name for var in domain.metas],
["som_cell", "som_row", "som_col", "som_error"])|
You incorrectly copied the test that I suggested. Please fix the indent. |
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## master #6763 +/- ##
==========================================
- Coverage 88.15% 88.15% -0.01%
==========================================
Files 323 323
Lines 70747 70748 +1
==========================================
- Hits 62369 62368 -1
- Misses 8378 8380 +2 |
Issue
Fixes #6750
Description of changes
Fixed TypeError: 'DiscreteVariable' object is not iterable.
Includes