Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: improve naming consistency in DataCombiner component #5471

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions src/backend/base/langflow/components/processing/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from .extract_key import ExtractDataKeyComponent
from .filter_data_values import DataFilterComponent
from .json_cleaner import JSONCleaner
from .merge_data import MergeDataComponent
from .merge_data import DataCombinerComponent
from .message_to_data import MessageToDataComponent
from .parse_data import ParseDataComponent
from .parse_json_data import ParseJSONDataComponent
Expand All @@ -16,10 +16,10 @@
"AlterMetadataComponent",
"CombineTextComponent",
"CreateDataComponent",
"DataCombinerComponent",
"DataFilterComponent",
"ExtractDataKeyComponent",
"JSONCleaner",
"MergeDataComponent",
"MessageToDataComponent",
"ParseDataComponent",
"ParseJSONDataComponent",
Expand Down
46 changes: 22 additions & 24 deletions src/backend/base/langflow/components/processing/merge_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,50 +8,48 @@
from langflow.schema import DataFrame


class MergeOperation(str, Enum):
CONCATENATE = "concatenate"
APPEND = "append"
MERGE = "merge"
JOIN = "join"
class DataOperation(str, Enum):
CONCATENATE = "Concatenate"
APPEND = "Append"
MERGE = "Merge"
JOIN = "Join"


class MergeDataComponent(Component):
display_name = "Merge Data"
description = "Combines data using merge operations"
class DataCombinerComponent(Component):
display_name = "Data Combiner"
description = "Combines data using different operations"
icon = "merge"

MIN_INPUTS_REQUIRED = 2

inputs = [
DataInput(name="data_inputs", display_name="Data Inputs", info="Dados para combinar", is_list=True),
DropdownInput(
name="operation",
display_name="Merge Operation",
options=[op.value for op in MergeOperation],
value=MergeOperation.CONCATENATE.value,
display_name="Operation Type",
options=[op.value for op in DataOperation],
value=DataOperation.CONCATENATE.value,
),
]
outputs = [Output(display_name="DataFrame", name="combined_data", method="combine_data")]

outputs = [Output(display_name="DataFrame", name="merged_data", method="merge_data")]

def merge_data(self) -> DataFrame:
def combine_data(self) -> DataFrame:
if not self.data_inputs or len(self.data_inputs) < self.MIN_INPUTS_REQUIRED:
empty_dataframe = DataFrame()
self.status = empty_dataframe
return empty_dataframe

operation = MergeOperation(self.operation)
operation = DataOperation(self.operation)
try:
merged_dataframe = self._process_operation(operation)
self.status = merged_dataframe
combined_dataframe = self._process_operation(operation)
self.status = combined_dataframe
except Exception as e:
logger.error(f"Erro durante operação {operation}: {e!s}")
raise
else:
return merged_dataframe
return combined_dataframe

def _process_operation(self, operation: MergeOperation) -> DataFrame:
if operation == MergeOperation.CONCATENATE:
def _process_operation(self, operation: DataOperation) -> DataFrame:
if operation == DataOperation.CONCATENATE:
combined_data: dict[str, str | object] = {}
for data_input in self.data_inputs:
for key, value in data_input.data.items():
Expand All @@ -64,11 +62,11 @@ def _process_operation(self, operation: MergeOperation) -> DataFrame:
combined_data[key] = value
return DataFrame([combined_data])

if operation == MergeOperation.APPEND:
if operation == DataOperation.APPEND:
rows = [data_input.data for data_input in self.data_inputs]
return DataFrame(rows)

if operation == MergeOperation.MERGE:
if operation == DataOperation.MERGE:
result_data: dict[str, str | list[str] | object] = {}
for data_input in self.data_inputs:
for key, value in data_input.data.items():
Expand All @@ -81,7 +79,7 @@ def _process_operation(self, operation: MergeOperation) -> DataFrame:
result_data[key] = value
return DataFrame([result_data])

if operation == MergeOperation.JOIN:
if operation == DataOperation.JOIN:
combined_data = {}
for idx, data_input in enumerate(self.data_inputs, 1):
for key, value in data_input.data.items():
Expand Down
Loading