refactor: improve naming consistency in DataCombiner component (#5471)
* refactor: improve naming consistency in DataCombiner component - Rename MergeOperation to DataOperation - Rename component to DataCombinerComponent - Convert operation enum values to uppercase - Update method names for consistency * [autofix.ci] apply automated fixes * fix: resolved linting errors in __init__.py * [autofix.ci] apply automated fixes * Changed operation names to capitalize only first letter * refactor: rename DataCombinerComponent to MergeDataComponent for better clarity and backwards compatibility * [autofix.ci] apply automated fixes * fix: Translate Portuguese text to English in merge_data.py * feat: add required to data_inputs in MergeDataComponent --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: Edwin Jose <edwin.jose@datastax.com>
This commit is contained in:
parent
303779e40a
commit
b55c9f1698
1 changed files with 23 additions and 25 deletions
|
|
@ -8,50 +8,48 @@ from langflow.io import DataInput, DropdownInput, Output
|
||||||
from langflow.schema import DataFrame
|
from langflow.schema import DataFrame
|
||||||
|
|
||||||
|
|
||||||
class MergeOperation(str, Enum):
|
class DataOperation(str, Enum):
|
||||||
CONCATENATE = "concatenate"
|
CONCATENATE = "Concatenate"
|
||||||
APPEND = "append"
|
APPEND = "Append"
|
||||||
MERGE = "merge"
|
MERGE = "Merge"
|
||||||
JOIN = "join"
|
JOIN = "Join"
|
||||||
|
|
||||||
|
|
||||||
class MergeDataComponent(Component):
|
class MergeDataComponent(Component):
|
||||||
display_name = "Merge Data"
|
display_name = "Data Combiner"
|
||||||
description = "Combines data using merge operations"
|
description = "Combines data using different operations"
|
||||||
icon = "merge"
|
icon = "merge"
|
||||||
|
|
||||||
MIN_INPUTS_REQUIRED = 2
|
MIN_INPUTS_REQUIRED = 2
|
||||||
|
|
||||||
inputs = [
|
inputs = [
|
||||||
DataInput(name="data_inputs", display_name="Data Inputs", info="Dados para combinar", is_list=True),
|
DataInput(name="data_inputs", display_name="Data Inputs", info="Data to combine", is_list=True, required=True),
|
||||||
DropdownInput(
|
DropdownInput(
|
||||||
name="operation",
|
name="operation",
|
||||||
display_name="Merge Operation",
|
display_name="Operation Type",
|
||||||
options=[op.value for op in MergeOperation],
|
options=[op.value for op in DataOperation],
|
||||||
value=MergeOperation.CONCATENATE.value,
|
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 combine_data(self) -> DataFrame:
|
||||||
|
|
||||||
def merge_data(self) -> DataFrame:
|
|
||||||
if not self.data_inputs or len(self.data_inputs) < self.MIN_INPUTS_REQUIRED:
|
if not self.data_inputs or len(self.data_inputs) < self.MIN_INPUTS_REQUIRED:
|
||||||
empty_dataframe = DataFrame()
|
empty_dataframe = DataFrame()
|
||||||
self.status = empty_dataframe
|
self.status = empty_dataframe
|
||||||
return empty_dataframe
|
return empty_dataframe
|
||||||
|
|
||||||
operation = MergeOperation(self.operation)
|
operation = DataOperation(self.operation)
|
||||||
try:
|
try:
|
||||||
merged_dataframe = self._process_operation(operation)
|
combined_dataframe = self._process_operation(operation)
|
||||||
self.status = merged_dataframe
|
self.status = combined_dataframe
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"Erro durante operação {operation}: {e!s}")
|
logger.error(f"Error during operation {operation}: {e!s}")
|
||||||
raise
|
raise
|
||||||
else:
|
else:
|
||||||
return merged_dataframe
|
return combined_dataframe
|
||||||
|
|
||||||
def _process_operation(self, operation: MergeOperation) -> DataFrame:
|
def _process_operation(self, operation: DataOperation) -> DataFrame:
|
||||||
if operation == MergeOperation.CONCATENATE:
|
if operation == DataOperation.CONCATENATE:
|
||||||
combined_data: dict[str, str | object] = {}
|
combined_data: dict[str, str | object] = {}
|
||||||
for data_input in self.data_inputs:
|
for data_input in self.data_inputs:
|
||||||
for key, value in data_input.data.items():
|
for key, value in data_input.data.items():
|
||||||
|
|
@ -64,11 +62,11 @@ class MergeDataComponent(Component):
|
||||||
combined_data[key] = value
|
combined_data[key] = value
|
||||||
return DataFrame([combined_data])
|
return DataFrame([combined_data])
|
||||||
|
|
||||||
if operation == MergeOperation.APPEND:
|
if operation == DataOperation.APPEND:
|
||||||
rows = [data_input.data for data_input in self.data_inputs]
|
rows = [data_input.data for data_input in self.data_inputs]
|
||||||
return DataFrame(rows)
|
return DataFrame(rows)
|
||||||
|
|
||||||
if operation == MergeOperation.MERGE:
|
if operation == DataOperation.MERGE:
|
||||||
result_data: dict[str, str | list[str] | object] = {}
|
result_data: dict[str, str | list[str] | object] = {}
|
||||||
for data_input in self.data_inputs:
|
for data_input in self.data_inputs:
|
||||||
for key, value in data_input.data.items():
|
for key, value in data_input.data.items():
|
||||||
|
|
@ -81,7 +79,7 @@ class MergeDataComponent(Component):
|
||||||
result_data[key] = value
|
result_data[key] = value
|
||||||
return DataFrame([result_data])
|
return DataFrame([result_data])
|
||||||
|
|
||||||
if operation == MergeOperation.JOIN:
|
if operation == DataOperation.JOIN:
|
||||||
combined_data = {}
|
combined_data = {}
|
||||||
for idx, data_input in enumerate(self.data_inputs, 1):
|
for idx, data_input in enumerate(self.data_inputs, 1):
|
||||||
for key, value in data_input.data.items():
|
for key, value in data_input.data.items():
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue