diff --git a/Orange/widgets/visualize/owboxplot.py b/Orange/widgets/visualize/owboxplot.py index 1d7021cab00..fdd927d3e5f 100644 --- a/Orange/widgets/visualize/owboxplot.py +++ b/Orange/widgets/visualize/owboxplot.py @@ -136,6 +136,9 @@ class OWBoxPlot(widget.OWWidget): graph_name = "box_scene" + class Warning(widget.OWWidget.Warning): + missing_values = widget.Msg("Variable consists of only missing values.") + def __init__(self): super().__init__() self.stats = [] @@ -292,11 +295,28 @@ def clear_scene(self): self.posthoc_lines = [] def layout_changed(self): - attr = self.attribute - if not attr: - return self.clear_scene() + if self.dataset is None or len(self.conts) == len(self.dist) == 0: + self.Warning.missing_values.clear() + return + + if len(self.conts): + if sum(self.conts.unknowns) == \ + len(self.dataset) and self.is_continuous: + self.Warning.missing_values() + return + if len(self.dist): + if self.dist.unknowns == len(self.dataset) and self.is_continuous: + self.Warning.missing_values() + return + + self.Warning.missing_values.clear() + self.layout_changed_repaint() + + def layout_changed_repaint(self): + attr = self.attribute + if not attr: return if not self.is_continuous: diff --git a/Orange/widgets/visualize/tests/test_owboxplot.py b/Orange/widgets/visualize/tests/test_owboxplot.py new file mode 100644 index 00000000000..9931f62b9fb --- /dev/null +++ b/Orange/widgets/visualize/tests/test_owboxplot.py @@ -0,0 +1,51 @@ +# Test methods with long descriptive names can omit docstrings +# pylint: disable=missing-docstring +import numpy as np +from Orange.data import Table, ContinuousVariable +from Orange.widgets.visualize.owboxplot import OWBoxPlot +from Orange.widgets.tests.base import WidgetTest + + +class TestOWBoxPlot(WidgetTest): + def setUp(self): + self.widget = self.create_widget(OWBoxPlot) + self.iris = Table("iris") + self.zoo = Table("zoo") + self.housing = Table("housing") + + def test_input_data(self): + """Check widget's data""" + self.assertEqual(self.widget.dataset, None) + self.send_signal("Data", self.iris) + self.assertEqual(self.widget.dataset, self.iris) + self.send_signal("Data", None) + self.assertEqual(self.widget.dataset, None) + + def test_input_data_missings_cont_group_var(self): + """Check widget with continuous data with missing values and group variable""" + data = self.iris + data.X[:, 0] = np.nan + self.send_signal("Data", data) + self.assertEqual(self.widget.dataset, data) + + def test_input_data_missings_cont_no_group_var(self): + """Check widget with continuous data with missing values and no group variable""" + data = self.housing + data.X[:, 0] = np.nan + self.send_signal("Data", data) + self.assertEqual(self.widget.dataset, data) + + 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 + self.send_signal("Data", data) + self.assertEqual(self.widget.dataset, data) + + 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 + self.send_signal("Data", data) + self.assertEqual(self.widget.dataset, data)