Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RFC][FIX] BoxPlot: Hide groups with no instances #3122

Merged
merged 3 commits into from
Jul 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions Orange/widgets/visualize/owboxplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,8 +407,11 @@ def compute_box_data(self):
dataset, attr, self.group_var)
if self.is_continuous:
self.stats = [BoxData(cont, attr, i, self.group_var)
for i, cont in enumerate(self.conts)]
self.label_txts_all = self.group_var.values
for i, cont in enumerate(self.conts)
if np.sum(cont) > 0]
self.label_txts_all = \
[v for v, c in zip(self.group_var.values, self.conts)
if np.sum(c) > 0]
else:
self.dist = distribution.get_distribution(dataset, attr)
self.conts = []
Expand Down Expand Up @@ -528,14 +531,17 @@ def display_changed_disc(self):
if self.group_var:
self.labels = [
QGraphicsTextItem("{}".format(int(sum(cont))))
for cont in self.conts]
for cont in self.conts if np.sum(cont) > 0]
else:
self.labels = [
QGraphicsTextItem(str(int(sum(self.dist))))]

self.draw_axis_disc()
if self.group_var:
self.boxes = [self.strudel(cont, i) for i, cont in enumerate(self.conts)]
self.boxes = \
[self.strudel(cont, i) for i, cont in enumerate(self.conts)
if np.sum(cont) > 0]
self.conts = self.conts[np.sum(np.array(self.conts), axis=1) > 0]
else:
self.boxes = [self.strudel(self.dist)]

Expand Down Expand Up @@ -767,6 +773,8 @@ def draw_axis_disc(self):
Draw the horizontal axis and sets self.scale_x for discrete attributes
"""
if self.stretched:
if not self.attr_labels:
return
step = steps = 10
else:
if self.group_var:
Expand Down
14 changes: 14 additions & 0 deletions Orange/widgets/visualize/tests/test_owboxplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,20 @@ def test_label_overlap(self):
QTest.qWait(3000)
self.widget.hide()

def test_empty_groups(self):
"""Test if groups with zero elements are not shown"""
table = Table("cyber-security-breaches")
self.send_signal(self.widget.Inputs.data, table)
self.__select_variable("US State")
self.__select_group("US State")
self.assertEqual(52, len(self.widget.boxes))

# select rows with US State equal to TX or MO
use_indexes = np.array([0, 1, 25, 26, 27])
table.X = table.X[use_indexes]
self.send_signal(self.widget.Inputs.data, table)
self.assertEqual(2, len(self.widget.boxes))

def _select_data(self):
items = [item for item in self.widget.box_scene.items()
if isinstance(item, FilterGraphicsRectItem)]
Expand Down