Skip to content

Commit 323a65b

Browse files
committed
[FIX] Silhouette Plot: now setting axis range properly
https://sentry.io/biolab/orange3/issues/220334718/
1 parent 334d2ea commit 323a65b

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

Orange/widgets/visualize/owsilhouetteplot.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ def commit(self):
389389

390390
if self._mask is not None:
391391
scores = np.full(shape=selectedmask.shape,
392-
fill_value=np.nan)
392+
fill_value=np.nan)
393393
scores[~self._mask] = self._silhouette
394394
else:
395395
scores = self._silhouette
@@ -589,13 +589,15 @@ def clear(self):
589589

590590
def __setup(self):
591591
# Setup the subwidgets/groups/layout
592-
smax = max((np.max(g.scores) for g in self.__groups
592+
smax = max((np.nanmax(g.scores) for g in self.__groups
593593
if g.scores.size),
594594
default=1)
595+
smax = 1 if np.isnan(smax) else smax
595596

596-
smin = min((np.min(g.scores) for g in self.__groups
597+
smin = min((np.nanmin(g.scores) for g in self.__groups
597598
if g.scores.size),
598599
default=-1)
600+
smin = -1 if np.isnan(smin) else smin
599601
smin = min(smin, 0)
600602

601603
font = self.font()

Orange/widgets/visualize/tests/test_owsilhouetteplot.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# pylint: disable=protected-access
12
# Test methods with long descriptive names can omit docstrings
23
# pylint: disable=missing-docstring
34
import random
@@ -6,6 +7,7 @@
67
import numpy as np
78

89
import Orange.data
10+
from Orange.data import Table, Domain, ContinuousVariable, DiscreteVariable
911
from Orange.widgets.utils.annotated_data import ANNOTATED_DATA_SIGNAL_NAME
1012
from Orange.widgets.visualize.owsilhouetteplot import OWSilhouettePlot
1113
from Orange.widgets.tests.base import WidgetTest, WidgetOutputsTestMixin
@@ -105,3 +107,21 @@ def test_memory_error(self):
105107
self.widget._effective_data = data
106108
self.widget._update()
107109
self.assertTrue(self.widget.Error.memory_error.is_shown())
110+
111+
def test_bad_data_range(self):
112+
"""
113+
Silhouette Plot now sets axis range properly.
114+
GH-2377
115+
"""
116+
nan = np.NaN
117+
table = Table(
118+
Domain(
119+
[ContinuousVariable("a"), ContinuousVariable("b"), ContinuousVariable("c")],
120+
[DiscreteVariable("d", values=["y", "n"])]),
121+
list(zip([4, nan, nan],
122+
[15, nan, nan],
123+
[16, nan, nan],
124+
"nyy"))
125+
)
126+
self.widget.controls.add_scores.setChecked(1)
127+
self.send_signal(self.widget.Inputs.data, table)

0 commit comments

Comments
 (0)