Skip to content

Commit

Permalink
Merge pull request #51 from jerneju/scoregenes-no-attributes
Browse files Browse the repository at this point in the history
[FIX] Score Genes: do not crash when no attributes
  • Loading branch information
lanzagar authored Feb 2, 2018
2 parents 670ef87 + 0a257b2 commit 055d513
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
37 changes: 37 additions & 0 deletions orangecontrib/single_cell/tests/test_owscoregenes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import unittest

from orangecontrib.single_cell.widgets.owscoregenes import OWRank
from Orange.widgets.tests.base import WidgetTest
from Orange.data import DiscreteVariable, ContinuousVariable, Domain, Table


class TestOWScoreGenes(WidgetTest):
def setUp(self):
self.widget = self.create_widget(OWRank)

def test_data_no_attributes(self):
"""
Do not crash when data has not attributes. Show an error.
GH-51
"""
w = self.widget

class_var = DiscreteVariable('Stage name', values=['STG1', 'STG2'])
metas = [ContinuousVariable('GeneName' + str(i)) for i in range(5)]
domain = Domain(attributes=[], class_vars=class_var, metas=metas)

data = Table(
domain,
[['STG1', 1, 2, 3, 4, 5],
['STG1', 4, 4, 4, 4, 4],
['STG1', 2, 3, 1, 1, 1],
['STG2', -1, 0, 1, 0, 0]])

self.assertFalse(w.Error.no_attributes.is_shown())
for is_shown, input_data in ((True, data), (False, None)):
self.send_signal(w.Inputs.data, input_data)
self.assertEqual(is_shown, w.Error.no_attributes.is_shown())


if __name__ == '__main__':
unittest.main()
5 changes: 5 additions & 0 deletions orangecontrib/single_cell/widgets/owscoregenes.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ class Information(OWWidget.Information):
class Error(OWWidget.Error):
invalid_type = Msg("Cannot handle target variable type {}")
inadequate_learner = Msg("Scorer {} inadequate: {}")
no_attributes = Msg("No attributes")

def __init__(self):
super().__init__()
Expand Down Expand Up @@ -410,6 +411,10 @@ def setData(self, data):
self.Information.missings_imputed(
shown=data is not None and data.has_missing())

if data is not None and not len(data.domain.attributes):
self.Error.no_attributes()
data = None

self.data = data
self.switchProblemType(ProblemType.CLASSIFICATION)
if self.data is not None:
Expand Down

0 comments on commit 055d513

Please sign in to comment.