Skip to content

Commit

Permalink
Predictions: Fix crash in error delegate when actual value is unknown (
Browse files Browse the repository at this point in the history
  • Loading branch information
janezd authored Oct 28, 2022
1 parent 29ecfa0 commit 5b67ff8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Orange/widgets/evaluate/owpredictions.py
Original file line number Diff line number Diff line change
Expand Up @@ -1124,7 +1124,7 @@ def displayText(self, value, _):

def drawBar(self, painter, option, index, rect):
value = self.cachedData(index, Qt.DisplayRole)
if numpy.isnan(value):
if value is None or numpy.isnan(value):
return

painter.save()
Expand Down Expand Up @@ -1210,7 +1210,7 @@ def drawBar(self, painter, option, index, rect):
if not self.span: # can be 0 if no errors, or None if they're hidden
return
error = self.cachedData(index, Qt.DisplayRole)
if numpy.isnan(error):
if error is None or numpy.isnan(error):
return
scaled = error / self.span

Expand Down
8 changes: 8 additions & 0 deletions Orange/widgets/evaluate/tests/test_owpredictions.py
Original file line number Diff line number Diff line change
Expand Up @@ -1839,6 +1839,10 @@ def test_drawBar(self):
delegate.drawBar(painter, Mock(), index, rect)
dr.assert_not_called()

delegate.cachedData = lambda *_: None
delegate.drawBar(painter, Mock(), index, rect)
dr.assert_not_called()

delegate.cachedData = lambda *_: 1 / 4
delegate.drawBar(painter, Mock(), index, rect)
dr.assert_called_once()
Expand Down Expand Up @@ -1876,6 +1880,10 @@ def test_drawBar(self):
delegate.drawBar(painter, Mock(), index, rect)
dr.assert_not_called()

delegate.cachedData = lambda *_: None
delegate.drawBar(painter, Mock(), index, rect)
dr.assert_not_called()

delegate.cachedData = lambda *_: 3
delegate.drawBar(painter, Mock(), index, rect)
r = dr.call_args[0][0]
Expand Down

0 comments on commit 5b67ff8

Please sign in to comment.