Skip to content

Commit

Permalink
Merge pull request #4496 from aturanjanin/owfeatureconstructor
Browse files Browse the repository at this point in the history
[ENH] OWFeatureConstructor: Data info displayed in the status bar
  • Loading branch information
VesnaT authored Mar 6, 2020
2 parents 9823706 + 8d796e1 commit 2b096e0
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
8 changes: 8 additions & 0 deletions Orange/widgets/data/owfeatureconstructor.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
from Orange.widgets.utils.sql import check_sql_input
from Orange.widgets import report
from Orange.widgets.utils.widgetpreview import WidgetPreview
from Orange.widgets.utils.state_summary import format_summary_details
from Orange.widgets.widget import OWWidget, Msg, Input, Output

FeatureDescriptor = \
Expand Down Expand Up @@ -494,6 +495,9 @@ def generate_newname(fmt):
self._on_selectedVariableChanged
)

self.info.set_input_summary(self.info.NoInput)
self.info.set_output_summary(self.info.NoOutput)

layout.addWidget(self.featureview)

box.layout().addLayout(layout, 1)
Expand Down Expand Up @@ -545,12 +549,14 @@ def setData(self, data=None):

self.data = data

self.info.set_input_summary(self.info.NoInput)
if self.data is not None:
descriptors = list(self.descriptors)
currindex = self.currentIndex
self.descriptors = []
self.currentIndex = -1
self.openContext(data)
self.info.set_input_summary(len(data), format_summary_details(data))

if descriptors != self.descriptors or \
self.currentIndex != currindex:
Expand All @@ -571,6 +577,7 @@ def handleNewSignals(self):
if self.data is not None:
self.apply()
else:
self.info.set_output_summary(self.info.NoOutput)
self.Outputs.data.send(None)

def addFeature(self, descriptor):
Expand Down Expand Up @@ -677,6 +684,7 @@ def report_error(err):
self.Error.more_values_needed(disc_attrs_not_ok)
return

self.info.set_output_summary(len(data), format_summary_details(data))
self.Outputs.data.send(data)

def send_report(self):
Expand Down
25 changes: 24 additions & 1 deletion Orange/widgets/data/tests/test_owfeatureconstructor.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
# pylint: disable=unsubscriptable-object
import unittest
import ast
import sys
import math
import pickle
import copy

from unittest.mock import Mock
import numpy as np

from Orange.data import (Table, Domain, StringVariable,
ContinuousVariable, DiscreteVariable, TimeVariable)
from Orange.widgets.tests.base import WidgetTest
from Orange.widgets.utils import vartype
from Orange.widgets.utils.itemmodels import PyListModel
from Orange.widgets.utils.state_summary import format_summary_details
from Orange.widgets.data.owfeatureconstructor import (
DiscreteDescriptor, ContinuousDescriptor, StringDescriptor,
construct_variables, OWFeatureConstructor,
Expand Down Expand Up @@ -306,7 +309,7 @@ def test_invalid_expression_variable(self):

class OWFeatureConstructorTests(WidgetTest):
def setUp(self):
self.widget = OWFeatureConstructor()
self.widget = self.create_widget(OWFeatureConstructor)

def test_create_variable_with_no_data(self):
self.widget.addFeature(
Expand Down Expand Up @@ -345,6 +348,26 @@ def test_discrete_no_values(self):
self.widget.apply()
self.assertTrue(self.widget.Error.more_values_needed.is_shown())

def test_summary(self):
"""Check if status bar is updated when data is received"""
data = Table("iris")
input_sum = self.widget.info.set_input_summary = Mock()
output_sum = self.widget.info.set_output_summary = Mock()

self.send_signal(self.widget.Inputs.data, data)
input_sum.assert_called_with(len(data), format_summary_details(data))
output = self.get_output(self.widget.Outputs.data)
output_sum.assert_called_with(len(output),
format_summary_details(output))

input_sum.reset_mock()
output_sum.reset_mock()
self.send_signal(self.widget.Inputs.data, None)
input_sum.assert_called_once()
self.assertEqual(input_sum.call_args[0][0].brief, "")
output_sum.assert_called_once()
self.assertEqual(output_sum.call_args[0][0].brief, "")


class TestFeatureEditor(unittest.TestCase):
def test_has_functions(self):
Expand Down

0 comments on commit 2b096e0

Please sign in to comment.