Skip to content

Commit

Permalink
Merge pull request #5308 from janezd/auto-summary
Browse files Browse the repository at this point in the history
[ENH] Automated and better summaries
  • Loading branch information
VesnaT authored May 7, 2021
2 parents ccea9ca + a2c278b commit ce6222e
Show file tree
Hide file tree
Showing 133 changed files with 183 additions and 2,627 deletions.
2 changes: 1 addition & 1 deletion Orange/preprocess/preprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"SklImpute", "Normalize", "Randomize", "Preprocess",
"RemoveConstant", "RemoveNaNClasses", "RemoveNaNColumns",
"ProjectPCA", "ProjectCUR", "Scale", "RemoveSparse",
"AdaptiveNormalize"]
"AdaptiveNormalize", "PreprocessorList"]


class Preprocess(Reprable):
Expand Down
9 changes: 0 additions & 9 deletions Orange/widgets/data/owaggregatecolumns.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
ContextSetting, Setting, DomainContextHandler
)
from Orange.widgets.utils.widgetpreview import WidgetPreview
from Orange.widgets.utils.state_summary import format_summary_details
from Orange.widgets.widget import Input, Output
from Orange.widgets.utils.itemmodels import DomainModel

Expand Down Expand Up @@ -80,22 +79,14 @@ def set_data(self, data: Table = None):
self.data = data
if self.data:
self.variable_model.set_domain(data.domain)
self.info.set_input_summary(len(self.data),
format_summary_details(self.data))
self.openContext(data)
else:
self.variable_model.set_domain(None)
self.info.set_input_summary(self.info.NoInput)
self.unconditional_commit()

def commit(self):
augmented = self._compute_data()
self.Outputs.data.send(augmented)
if augmented is None:
self.info.set_output_summary(self.info.NoOutput)
else:
self.info.set_output_summary(
len(augmented), format_summary_details(augmented))

def _compute_data(self):
if not self.data or not self.variables:
Expand Down
9 changes: 0 additions & 9 deletions Orange/widgets/data/owcolor.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
from Orange.widgets.gui import HorizontalGridDelegate
from Orange.widgets.utils import itemmodels, colorpalettes
from Orange.widgets.utils.widgetpreview import WidgetPreview
from Orange.widgets.utils.state_summary import format_summary_details
from Orange.widgets.report import colored_square as square
from Orange.widgets.widget import Input, Output

Expand Down Expand Up @@ -580,9 +579,6 @@ def __init__(self):
gui.rubber(self.buttonsArea)
gui.auto_apply(self.buttonsArea, self, "auto_apply")

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

@staticmethod
def sizeHint(): # pragma: no cover
return QSize(500, 570)
Expand All @@ -594,10 +590,8 @@ def set_data(self, data):
self.cont_descs = []
if data is None:
self.data = self.domain = None
self.info.set_input_summary(self.info.NoInput)
else:
self.data = data
self.info.set_input_summary(len(data), format_summary_details(data))
for var in chain(data.domain.variables, data.domain.metas):
if var.is_discrete:
self.disc_descs.append(DiscAttrDesc(var))
Expand Down Expand Up @@ -738,7 +732,6 @@ def make(variables):

if self.data is None:
self.Outputs.data.send(None)
self.info.set_output_summary(self.info.NoOutput)
return

disc_dict = {desc.var.name: desc for desc in self.disc_descs}
Expand All @@ -748,8 +741,6 @@ def make(variables):
new_domain = Orange.data.Domain(
make(dom.attributes), make(dom.class_vars), make(dom.metas))
new_data = self.data.transform(new_domain)
self.info.set_output_summary(len(new_data),
format_summary_details(new_data))
self.Outputs.data.send(new_data)

def send_report(self):
Expand Down
24 changes: 0 additions & 24 deletions Orange/widgets/data/owconcatenate.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
from Orange.widgets.utils.annotated_data import add_columns
from Orange.widgets.utils.sql import check_sql_input
from Orange.widgets.utils.widgetpreview import WidgetPreview
from Orange.widgets.utils.state_summary import format_summary_details, \
format_multiple_summaries
from Orange.widgets.widget import Input, Output, Msg


Expand Down Expand Up @@ -145,9 +143,6 @@ def __init__(self):
gui.comboBox(ibox, self, "source_column_role", items=self.id_roles,
callback=self._source_changed))

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

ibox.layout().addLayout(form)
mleft, mtop, mright, _ = ibox.layout().getContentsMargins()
ibox.layout().setContentsMargins(mleft, mtop, mright, 4)
Expand All @@ -170,25 +165,8 @@ def set_more_data(self, data=None, sig_id=None):
elif sig_id in self.more_data:
del self.more_data[sig_id]

def _set_input_summary(self):
more_data = list(self.more_data.values()) if self.more_data else [None]
n_primary = len(self.primary_data) if self.primary_data else 0
n_more_data = [len(data) if data else 0 for data in more_data]

summary, details, kwargs = self.info.NoInput, "", {}
if self.primary_data or self.more_data:
summary = f"{self.info.format_number(n_primary)}, " \
+ ", ".join(self.info.format_number(i) for i in n_more_data)
details = format_multiple_summaries(
[("Primary data", self.primary_data)]
+ [("", data) for data in more_data]
)
kwargs = {"format": Qt.RichText}
self.info.set_input_summary(summary, details, **kwargs)

def handleNewSignals(self):
self.mergebox.setDisabled(self.primary_data is not None)
self._set_input_summary()
if self.incompatible_types():
self.Error.bow_concatenation()
else:
Expand Down Expand Up @@ -242,10 +220,8 @@ def apply(self):
source_ids = np.array(list(flatten(
[i] * len(table) for i, table in enumerate(tables)))).reshape((-1, 1))
data[:, source_var] = source_ids
self.info.set_output_summary(len(data), format_summary_details(data))
else:
data = None
self.info.set_output_summary(self.info.NoOutput)

self.Outputs.data.send(data)

Expand Down
9 changes: 0 additions & 9 deletions Orange/widgets/data/owcontinuize.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
from Orange.widgets.settings import Setting
from Orange.widgets.utils.sql import check_sql_input
from Orange.widgets.utils.widgetpreview import WidgetPreview
from Orange.widgets.utils.state_summary import format_summary_details
from Orange.widgets.widget import Input, Output


Expand Down Expand Up @@ -99,8 +98,6 @@ def __init__(self):
gui.auto_apply(self.buttonsArea, self, "autosend")

self.data = None
self.info.set_input_summary(self.info.NoInput)
self.info.set_output_summary(self.info.NoOutput)

def settings_changed(self):
self.commit()
Expand All @@ -111,12 +108,8 @@ def setData(self, data):
self.data = data
self.enable_normalization()
if data is None:
self.info.set_input_summary(self.info.NoInput)
self.info.set_output_summary(self.info.NoOutput)
self.Outputs.data.send(None)
else:
self.info.set_input_summary(len(data),
format_summary_details(data))
self.unconditional_commit()

def enable_normalization(self):
Expand Down Expand Up @@ -147,8 +140,6 @@ def commit(self):
domain = continuizer(self.data)
data = self.data.transform(domain)
self.Outputs.data.send(data)
self.info.set_output_summary(len(data),
format_summary_details(data))
else:
self.Outputs.data.send(self.data) # None or empty data

Expand Down
11 changes: 0 additions & 11 deletions Orange/widgets/data/owcorrelations.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
from Orange.widgets.utils.itemmodels import DomainModel
from Orange.widgets.utils.signals import Input, Output
from Orange.widgets.utils.widgetpreview import WidgetPreview
from Orange.widgets.utils.state_summary import format_summary_details
from Orange.widgets.visualize.utils import VizRankDialogAttrPair
from Orange.widgets.widget import OWWidget, AttributeList, Msg

Expand Down Expand Up @@ -297,9 +296,6 @@ def __init__(self):
button_box = gui.hBox(self.buttonsArea)
button_box.layout().addWidget(self.vizrank.button)

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

@staticmethod
def sizeHint():
return QSize(350, 400)
Expand Down Expand Up @@ -366,10 +362,6 @@ def set_data(self, data):
self.Warning.not_enough_vars()
else:
self.cont_data = SklImpute()(cont_data)
self.info.set_input_summary(len(data),
format_summary_details(data))
else:
self.info.set_input_summary(self.info.NoInput)
self.set_feature_model()
self.openContext(self.cont_data)
self.apply()
Expand All @@ -394,9 +386,6 @@ def apply(self):

def commit(self):
self.Outputs.data.send(self.data)
summary = len(self.data) if self.data else self.info.NoOutput
details = format_summary_details(self.data) if self.data else ""
self.info.set_output_summary(summary, details)

if self.data is None or self.cont_data is None:
self.Outputs.features.send(None)
Expand Down
13 changes: 0 additions & 13 deletions Orange/widgets/data/owcreateclass.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
from Orange.widgets.settings import DomainContextHandler, ContextSetting
from Orange.widgets.utils.itemmodels import DomainModel
from Orange.widgets.utils.widgetpreview import WidgetPreview
from Orange.widgets.utils.state_summary import format_summary_details
from Orange.widgets.widget import Msg, Input, Output


Expand Down Expand Up @@ -269,9 +268,6 @@ def __init__(self):

gui.button(self.buttonsArea, self, "Apply", callback=self.apply)

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

# TODO: Resizing upon changing the number of rules does not work
self.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Maximum)

Expand All @@ -297,16 +293,12 @@ def set_data(self, data):
self.closeContext()
self.rules = {}
self.data = data
summary = len(data) if data else self.info.NoInput
details = format_summary_details(data) if data else ""
self.info.set_input_summary(summary, details)
model = self.controls.attribute.model()
model.set_domain(data.domain if data is not None else None)
self.Warning.no_nonnumeric_vars(shown=data is not None and not model)
if not model:
self.attribute = None
self.Outputs.data.send(None)
self.info.set_output_summary(self.info.NoOutput)
return
self.attribute = model[0]
self.openContext(data)
Expand Down Expand Up @@ -513,7 +505,6 @@ def apply(self):
self.class_name = self.class_name.strip()
if not self.attribute:
self.Outputs.data.send(None)
self.info.set_output_summary(self.info.NoOutput)
return
domain = self.data.domain
if not self.class_name:
Expand All @@ -522,15 +513,11 @@ def apply(self):
self.Error.class_name_duplicated()
if not self.class_name or self.class_name in domain:
self.Outputs.data.send(None)
self.info.set_output_summary(self.info.NoOutput)
return
new_class = self._create_variable()
new_domain = Domain(
domain.attributes, new_class, domain.metas + domain.class_vars)
new_data = self.data.transform(new_domain)
summary = len(new_data) if new_data is not None else self.info.NoOutput
details = format_summary_details(new_data) if new_data is not None else ""
self.info.set_output_summary(summary, details)
self.Outputs.data.send(new_data)

def _create_variable(self):
Expand Down
27 changes: 0 additions & 27 deletions Orange/widgets/data/owcreateinstance.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
from Orange.widgets import gui
from Orange.widgets.utils.itemmodels import TableModel
from Orange.widgets.settings import Setting
from Orange.widgets.utils.state_summary import format_summary_details, \
format_multiple_summaries
from Orange.widgets.utils.widgetpreview import WidgetPreview
from Orange.widgets.widget import OWWidget, Input, Output, Msg

Expand Down Expand Up @@ -527,8 +525,6 @@ def __init__(self):
gui.rubber(self.buttonsArea)
box = gui.auto_apply(self.buttonsArea, self, "auto_commit")

self._set_input_summary()
self._set_output_summary()
self.settingsAboutToBePacked.connect(self.pack_settings)

def __filter_edit_changed(self):
Expand Down Expand Up @@ -604,7 +600,6 @@ def _initialize_values(self, fun: str, indices: List[QModelIndex] = None):
@Inputs.data
def set_data(self, data: Table):
self.data = data
self._set_input_summary()
self._set_model_data()
self.unconditional_commit()

Expand All @@ -624,35 +619,13 @@ def _set_model_data(self):
@Inputs.reference
def set_reference(self, data: Table):
self.reference = data
self._set_input_summary()

def _set_input_summary(self):
n_data = len(self.data) if self.data else 0
n_refs = len(self.reference) if self.reference else 0
summary, details, kwargs = self.info.NoInput, "", {}

if self.data or self.reference:
summary = f"{self.info.format_number(n_data)}, " \
f"{self.info.format_number(n_refs)}"
data_list = [("Data", self.data), ("Reference", self.reference)]
details = format_multiple_summaries(data_list)
kwargs = {"format": Qt.RichText}
self.info.set_input_summary(summary, details, **kwargs)

def _set_output_summary(self, data: Optional[Table] = None):
if data:
summary, details = len(data), format_summary_details(data)
else:
summary, details = self.info.NoOutput, ""
self.info.set_output_summary(summary, details)

def commit(self):
output_data = None
if self.data:
output_data = self._create_data_from_values()
if self.append_to_data:
output_data = self._append_to_data(output_data)
self._set_output_summary(output_data)
self.Outputs.data.send(output_data)

def _create_data_from_values(self) -> Table:
Expand Down
22 changes: 8 additions & 14 deletions Orange/widgets/data/owcsvimport.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@
from Orange.widgets.utils.settings import (
QSettings_readArray, QSettings_writeArray
)
from Orange.widgets.utils.state_summary import format_summary_details

if typing.TYPE_CHECKING:
# pylint: disable=invalid-name
Expand Down Expand Up @@ -605,17 +604,17 @@ class OWCSVFileImport(widget.OWWidget):
category = "Data"
keywords = ["file", "load", "read", "open", "csv"]

outputs = [
widget.OutputSignal(
class Outputs:
data = widget.Output(
name="Data",
type=Orange.data.Table,
doc="Loaded data set."),
widget.OutputSignal(
doc="Loaded data set.")
data_frame = widget.Output(
name="Data Frame",
type=pd.DataFrame,
doc=""
doc="",
auto_summary=False
)
]

class Error(widget.OWWidget.Error):
error = widget.Msg(
Expand Down Expand Up @@ -714,8 +713,6 @@ def __init__(self, *args, **kwargs):
self.summary_text.viewport().setAutoFillBackground(False)
box.layout().addWidget(self.summary_text)

self.info.set_output_summary(self.info.NoOutput)

button_box = QDialogButtonBox(
orientation=Qt.Horizontal,
standardButtons=QDialogButtonBox.Cancel | QDialogButtonBox.Retry
Expand Down Expand Up @@ -1216,14 +1213,11 @@ def __handle_result(self, f):
table.name = os.path.splitext(os.path.split(filename)[-1])[0]
else:
table = None
self.send("Data Frame", df)
self.send('Data', table)
self.Outputs.data_frame.send(df)
self.Outputs.data.send(table)
self._update_status_messages(table)

def _update_status_messages(self, data):
summary = len(data) if data else self.info.NoOutput
details = format_summary_details(data) if data else ""
self.info.set_output_summary(summary, details)
if data is None:
return

Expand Down
Loading

0 comments on commit ce6222e

Please sign in to comment.