Skip to content

Commit 920ced4

Browse files
committed
OWBoxPlot: Fix crash on discrete variables with no values
1 parent 5369032 commit 920ced4

File tree

2 files changed

+31
-4
lines changed

2 files changed

+31
-4
lines changed

Orange/widgets/visualize/owboxplot.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,8 @@ def compute_score(attr):
297297
else:
298298
# Chi-square with the given distribution into groups
299299
# (see degrees of freedom in computation of the p-value)
300+
if not attr.values or not group_var.values:
301+
return 2
300302
observed = np.array(
301303
contingency.get_contingency(data, group_var, attr))
302304
observed = observed[observed.sum(axis=1) != 0, :]
@@ -368,10 +370,11 @@ def compute_box_data(self):
368370
if not attr:
369371
return
370372
dataset = self.dataset
371-
if dataset is None:
373+
self.is_continuous = attr.is_continuous
374+
if dataset is None or not self.is_continuous and not attr.values or \
375+
self.group_var and not self.group_var.values:
372376
self.stats = self.dist = self.conts = []
373377
return
374-
self.is_continuous = attr.is_continuous
375378
if self.group_var:
376379
self.dist = []
377380
self.conts = contingency.get_contingency(
@@ -554,6 +557,8 @@ def stat_ttest():
554557
df = pooled_var ** 2 / \
555558
((d1.var / d1.n) ** 2 / (d1.n - 1) +
556559
(d2.var / d2.n) ** 2 / (d2.n - 1))
560+
if pooled_var == 0:
561+
return np.nan, np.nan
557562
t = abs(d1.mean - d2.mean) / math.sqrt(pooled_var)
558563
p = 2 * (1 - scipy.special.stdtr(df, t))
559564
return t, p

Orange/widgets/visualize/tests/test_owboxplot.py

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,37 @@ def test_input_data_missings_cont_no_group_var(self):
5656
def test_input_data_missings_disc_group_var(self):
5757
"""Check widget with discrete data with missing values and group variable"""
5858
data = self.zoo
59-
data.X[:, 0] = np.nan
59+
data.X[:, 1] = np.nan
60+
data.domain.attributes[1].values = []
6061
self.send_signal("Data", data)
62+
self.widget.controls.order_by_importance.setChecked(True)
63+
self._select_list_items(self.widget.controls.attribute)
64+
self._select_list_items(self.widget.controls.group_var)
6165

6266
def test_input_data_missings_disc_no_group_var(self):
6367
"""Check widget discrete data with missing values and no group variable"""
6468
data = self.zoo
6569
data.domain.class_var = ContinuousVariable("cls")
66-
data.X[:, 0] = np.nan
70+
data.X[:, 1] = np.nan
71+
data.domain.attributes[1].values = []
72+
self.send_signal("Data", data)
73+
self.widget.controls.order_by_importance.setChecked(True)
74+
self._select_list_items(self.widget.controls.attribute)
75+
self._select_list_items(self.widget.controls.group_var)
76+
77+
def test_attribute_combinations(self):
78+
data = Table("anneal")
6779
self.send_signal("Data", data)
80+
group_list = self.widget.controls.group_var
81+
m = group_list.selectionModel()
82+
for i in range(len(group_list.model())):
83+
m.setCurrentIndex(group_list.model().index(i), m.ClearAndSelect)
84+
self._select_list_items(self.widget.controls.attribute)
85+
86+
def _select_list_items(self, _list):
87+
model = _list.selectionModel()
88+
for i in range(len(_list.model())):
89+
model.setCurrentIndex(_list.model().index(i), model.ClearAndSelect)
6890

6991
def test_apply_sorting(self):
7092
controls = self.widget.controls

0 commit comments

Comments
 (0)