Skip to content

Commit

Permalink
OWPredictions: Fix failure after failed predictor
Browse files Browse the repository at this point in the history
  • Loading branch information
janezd committed Oct 28, 2018
1 parent 7ee820f commit 2a3adca
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
4 changes: 3 additions & 1 deletion Orange/widgets/evaluate/owpredictions.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,9 @@ def handleNewSignals(self):

def _call_predictors(self):
for inputid, pred in self.predictors.items():
if pred.results is None or numpy.isnan(pred.results[0]).all():
if pred.results is None \
or isinstance(pred.results, str) \
or numpy.isnan(pred.results[0]).all():
try:
results = self.predict(pred.predictor, self.data)
except ValueError as err:
Expand Down
14 changes: 13 additions & 1 deletion Orange/widgets/evaluate/tests/test_owpredictions.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
"""Tests for OWPredictions"""
import io
from unittest.mock import Mock

import numpy as np
from Orange.base import Model

from Orange.data.io import TabReader
from Orange.widgets.tests.base import WidgetTest
Expand All @@ -27,7 +30,6 @@ def test_nan_target_input(self):
data = self.iris[::10].copy()
data.Y[1] = np.nan
yvec, _ = data.get_column_view(data.domain.class_var)
nanmask = np.isnan(yvec)
self.send_signal(self.widget.Inputs.data, data)
self.send_signal(self.widget.Inputs.predictors, ConstantLearner()(data), 1)
pred = self.get_output(self.widget.Outputs.predictions)
Expand Down Expand Up @@ -170,3 +172,13 @@ def test_continuous_class(self):
cl_data = ConstantLearner()(data)
self.send_signal(self.widget.Inputs.predictors, cl_data, 1)
self.send_signal(self.widget.Inputs.data, data)

def test_predictor_fails(self):
titanic = Table("titanic")
failing_model = ConstantLearner()(titanic)
failing_model.predict = Mock(side_effect=ValueError("foo"))
self.send_signal(self.widget.Inputs.predictors, failing_model, 1)
self.send_signal(self.widget.Inputs.data, titanic)

model2 = ConstantLearner()(titanic)
self.send_signal(self.widget.Inputs.predictors, model2, 2)

0 comments on commit 2a3adca

Please sign in to comment.