Skip to content

Commit

Permalink
OWBoxPlot: Fix crash on discrete variables with no values
Browse files Browse the repository at this point in the history
  • Loading branch information
VesnaT committed Dec 1, 2016
1 parent 5369032 commit 920ced4
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
9 changes: 7 additions & 2 deletions Orange/widgets/visualize/owboxplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,8 @@ def compute_score(attr):
else:
# Chi-square with the given distribution into groups
# (see degrees of freedom in computation of the p-value)
if not attr.values or not group_var.values:
return 2
observed = np.array(
contingency.get_contingency(data, group_var, attr))
observed = observed[observed.sum(axis=1) != 0, :]
Expand Down Expand Up @@ -368,10 +370,11 @@ def compute_box_data(self):
if not attr:
return
dataset = self.dataset
if dataset is None:
self.is_continuous = attr.is_continuous
if dataset is None or not self.is_continuous and not attr.values or \
self.group_var and not self.group_var.values:
self.stats = self.dist = self.conts = []
return
self.is_continuous = attr.is_continuous
if self.group_var:
self.dist = []
self.conts = contingency.get_contingency(
Expand Down Expand Up @@ -554,6 +557,8 @@ def stat_ttest():
df = pooled_var ** 2 / \
((d1.var / d1.n) ** 2 / (d1.n - 1) +
(d2.var / d2.n) ** 2 / (d2.n - 1))
if pooled_var == 0:
return np.nan, np.nan
t = abs(d1.mean - d2.mean) / math.sqrt(pooled_var)
p = 2 * (1 - scipy.special.stdtr(df, t))
return t, p
Expand Down
26 changes: 24 additions & 2 deletions Orange/widgets/visualize/tests/test_owboxplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,37 @@ def test_input_data_missings_cont_no_group_var(self):
def test_input_data_missings_disc_group_var(self):
"""Check widget with discrete data with missing values and group variable"""
data = self.zoo
data.X[:, 0] = np.nan
data.X[:, 1] = np.nan
data.domain.attributes[1].values = []
self.send_signal("Data", data)
self.widget.controls.order_by_importance.setChecked(True)
self._select_list_items(self.widget.controls.attribute)
self._select_list_items(self.widget.controls.group_var)

def test_input_data_missings_disc_no_group_var(self):
"""Check widget discrete data with missing values and no group variable"""
data = self.zoo
data.domain.class_var = ContinuousVariable("cls")
data.X[:, 0] = np.nan
data.X[:, 1] = np.nan
data.domain.attributes[1].values = []
self.send_signal("Data", data)
self.widget.controls.order_by_importance.setChecked(True)
self._select_list_items(self.widget.controls.attribute)
self._select_list_items(self.widget.controls.group_var)

def test_attribute_combinations(self):
data = Table("anneal")
self.send_signal("Data", data)
group_list = self.widget.controls.group_var
m = group_list.selectionModel()
for i in range(len(group_list.model())):
m.setCurrentIndex(group_list.model().index(i), m.ClearAndSelect)
self._select_list_items(self.widget.controls.attribute)

def _select_list_items(self, _list):
model = _list.selectionModel()
for i in range(len(_list.model())):
model.setCurrentIndex(_list.model().index(i), model.ClearAndSelect)

def test_apply_sorting(self):
controls = self.widget.controls
Expand Down

0 comments on commit 920ced4

Please sign in to comment.