Skip to content
Open
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
31 changes: 27 additions & 4 deletions Orange/widgets/data/owmergedata.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,15 +243,26 @@ def matches(part, variables):

class OWMergeData(widget.OWWidget):
name = "Merge Data"
description = "Merge datasets based on the values of selected features."
description = (
"Merge two datasets by matching selected features. "
"Connect the primary table to Data and the second table to "
"Extra Data (second table)."
)
category = "Transform"
icon = "icons/MergeData.svg"
priority = 1110
keywords = "merge data, join"

class Inputs:
data = Input("Data", Orange.data.Table, default=True, replaces=["Data A"])
extra_data = Input("Extra Data", Orange.data.Table, replaces=["Data B"])
data = Input(
"Data", Orange.data.Table, default=True,
doc="Primary / left table. Rows you usually want to keep.",
replaces=["Data A"])
extra_data = Input(
"Extra Data (second table)", Orange.data.Table,
doc="Second / right table to merge from. "
"Connect a different widget here - not the same link as Data.",
replaces=["Extra Data", "Data B"])

class Outputs:
data = Output("Data",
Expand All @@ -260,7 +271,7 @@ class Outputs:
dynamic=False)

LeftJoin, InnerJoin, OuterJoin = range(3)
OptionNames = ("Append columns from Extra data",
OptionNames = ("Append columns from Extra Data",
"Find matching pairs of rows",
"Concatenate tables")
OptionDescriptions = (
Expand Down Expand Up @@ -292,6 +303,12 @@ class Outputs:
want_main_area = False
resizing_enabled = False

class Information(widget.OWWidget.Information):
need_both_tables = Msg(
"Connect both inputs: Data (main table) and "
"Extra Data (second table).\n"
"Each must come from a different source.")

class Warning(widget.OWWidget.Warning):
renamed_vars = Msg("Some variables have been renamed "
"to avoid duplicates.\n{}")
Expand Down Expand Up @@ -332,6 +349,10 @@ def __init__(self):
self.model = DomainModelWithTooltips(content)
self.extra_model = DomainModelWithTooltips(content)

gui.label(
self.controlArea, self,
"Inputs: Data = main table · Extra Data = second table to merge")

grp = gui.radioButtons(
self.controlArea, self, "merging", box="Merging",
btnLabels=self.OptionNames, tooltips=self.OptionDescriptions,
Expand Down Expand Up @@ -397,6 +418,8 @@ def get_unique_str_metas_names(model_):
@gui.deferred
def commit(self):
self.clear_messages()
if bool(self.data) ^ bool(self.extra_data):
self.Information.need_both_tables()
merged = self.merge() if self.data and self.extra_data else None
self.Outputs.data.send(merged)

Expand Down