Skip to content

Commit 000bcad

Browse files
authored
Merge pull request #3165 from ales-erjavec/fixes/box-plot-empty-contingency-check
[FIX] OWBoxPlot: Fix empty continuous contingency check
2 parents 3d97116 + 9763f6d commit 000bcad

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

Orange/widgets/visualize/owboxplot.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -427,12 +427,17 @@ def compute_box_data(self):
427427
self.conts = contingency.get_contingency(
428428
dataset, attr, self.group_var)
429429
if self.is_continuous:
430-
self.stats = [BoxData(cont, attr, i, self.group_var)
431-
for i, cont in enumerate(self.conts)
432-
if np.sum(cont) > 0]
433-
self.label_txts_all = \
434-
[v for v, c in zip(self.group_var.values, self.conts)
435-
if np.sum(c) > 0]
430+
stats, label_texts = [], []
431+
for i, cont in enumerate(self.conts):
432+
if np.sum(cont[1]):
433+
stats.append(BoxData(cont, attr, i, self.group_var))
434+
label_texts.append(self.group_var.values[i])
435+
self.stats = stats
436+
self.label_txts_all = label_texts
437+
else:
438+
self.label_txts_all = \
439+
[v for v, c in zip(self.group_var.values, self.conts)
440+
if np.sum(c) > 0]
436441
else:
437442
self.dist = distribution.get_distribution(dataset, attr)
438443
self.conts = []
@@ -544,6 +549,7 @@ def display_changed(self):
544549
self.select_box_items()
545550

546551
def display_changed_disc(self):
552+
assert not self.is_continuous
547553
self.clear_scene()
548554
self.attr_labels = [QGraphicsSimpleTextItem(lab)
549555
for lab in self.label_txts_all]
@@ -608,6 +614,7 @@ def __draw_row_counts(self, y, row):
608614
row: int
609615
row index
610616
"""
617+
assert not self.is_continuous
611618
label = self.labels[row]
612619
b = label.boundingRect()
613620
if self.group_var:
@@ -793,6 +800,7 @@ def draw_axis_disc(self):
793800
"""
794801
Draw the horizontal axis and sets self.scale_x for discrete attributes
795802
"""
803+
assert not self.is_continuous
796804
if self.stretched:
797805
if not self.attr_labels:
798806
return

Orange/widgets/visualize/tests/test_owboxplot.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
import numpy as np
66
from AnyQt.QtCore import QItemSelectionModel
7-
from AnyQt.QtTest import QTest
87

98
from Orange.data import Table, ContinuousVariable, StringVariable, Domain
109
from Orange.widgets.visualize.owboxplot import (
@@ -161,9 +160,9 @@ def test_label_overlap(self):
161160
self.widget.stretched = False
162161
self.__select_variable("chest pain")
163162
self.__select_group("gender")
164-
self.widget.show()
165-
QTest.qWait(3000)
166-
self.widget.hide()
163+
self.widget.adjustSize()
164+
self.widget.layout().activate()
165+
self.widget.grab() # ensure that the painting code is run
167166

168167
def test_empty_groups(self):
169168
"""Test if groups with zero elements are not shown"""

0 commit comments

Comments
 (0)