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

feat: add dataframe to Loop component, fixes loop input error #6996

Open
wants to merge 20 commits into
base: main
Choose a base branch
from

Conversation

rodrigosnader
Copy link
Contributor

@rodrigosnader rodrigosnader commented Mar 10, 2025

This pull request introduces several changes to the LoopComponent class in the langflow backend to support both Data and DataFrame types. The modifications include updates to the input handling, validation, and output methods, as well as adjustments to the initial setup templates.

Changes to LoopComponent class:

  • Updated import statements to include DataFrame and changed DataInput to HandleInput. (src/backend/base/langflow/components/logic/loop.py)
  • Modified the inputs attribute to accept both Data and DataFrame types and updated the display name and info accordingly. (src/backend/base/langflow/components/logic/loop.py)
  • Enhanced the _validate_data method to handle DataFrame inputs and convert them to a list of Data objects. (src/backend/base/langflow/components/logic/loop.py)
  • Changed the done_output method to return a DataFrame instead of a Data object when the iteration is complete. (src/backend/base/langflow/components/logic/loop.py)
  • Updated the aggregated_output method to return a list of Data objects. (src/backend/base/langflow/components/logic/loop.py)

Changes to initial setup templates:

  • Modified LoopTemplate.json to reflect the changes in input and output types, including the addition of DataFrame as a valid type. (src/backend/base/langflow/initial_setup/starter_projects/LoopTemplate.json) [1] [2] [3] [4] [5] [6]

These changes enhance the flexibility of the LoopComponent by allowing it to handle both Data and DataFrame inputs, making it more versatile for different data processing scenarios.

@dosubot dosubot bot added size:S This PR changes 10-29 lines, ignoring generated files. enhancement New feature or request labels Mar 10, 2025
@dosubot dosubot bot added size:M This PR changes 30-99 lines, ignoring generated files. and removed size:S This PR changes 10-29 lines, ignoring generated files. labels Mar 10, 2025
@edwinjosechittilappilly edwinjosechittilappilly changed the title add dataframe support for the loop component feat: add dataframe support for the loop component Mar 11, 2025
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Overview

This pull request adds support for DataFrame inputs and outputs in the LoopComponent, enhancing its data handling flexibility. Key changes include:

  • Replacing DataInput with HandleInput and updating the input metadata to accept both Data and DataFrame.
  • Modifying _validate_data to convert DataFrame inputs into a list of Data objects.
  • Changing done_output to return a DataFrame when iteration is complete.

Reviewed Changes

File Description
src/backend/base/langflow/components/logic/loop.py Updates to inputs, validation, and output methods to incorporate DataFrame support

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

Comments suppressed due to low confidence (1)

src/backend/base/langflow/components/logic/loop.py:84

  • [nitpick] The method name 'done_output' may not clearly indicate that it returns a DataFrame. Consider updating the name or adding documentation to clarify this behavior for improved code clarity.
def done_output(self) -> DataFrame:

Comment on lines 104 to 105
def aggregated_output(self) -> list[Data]:
"""Return the aggregated list once all items are processed."""
Copy link
Preview

Copilot AI Mar 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The method 'aggregated_output' returns a list of Data objects, while 'done_output' now returns a DataFrame. This discrepancy in return types may lead to inconsistencies when consuming these outputs; consider unifying the output types or clearly documenting the differences in behavior.

Suggested change
def aggregated_output(self) -> list[Data]:
"""Return the aggregated list once all items are processed."""
def aggregated_output(self) -> DataFrame:
"""Return the aggregated DataFrame once all items are processed."""

Copilot is powered by AI, so mistakes are possible. Review output carefully before use.

Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
@github-actions github-actions bot added enhancement New feature or request and removed enhancement New feature or request labels Mar 11, 2025
Copy link

codspeed-hq bot commented Mar 11, 2025

CodSpeed Performance Report

Merging #6996 will degrade performances by 35.52%

Comparing loop_component_dataframe_support (5a357b6) with main (58e0d42)

Summary

❌ 2 regressions
✅ 17 untouched benchmarks

⚠️ Please fix the performance issues or acknowledge them on CodSpeed.

Benchmarks breakdown

Benchmark BASE HEAD Change
test_build_flow_invalid_job_id 8 ms 12.4 ms -35.52%
test_cancel_nonexistent_build 7.7 ms 9.4 ms -17.53%

@edwinjosechittilappilly
Copy link
Collaborator

Testing,

We might need to deplrecate the old one as well as update the template.

cc. @italojohnny May I know if you are already working on it if not I could pick it up!

@italojohnny
Copy link
Member

Testing,

We might need to deplrecate the old one as well as update the template.

cc. @italojohnny May I know if you are already working on it if not I could pick it up!

I haven’t had time to check this PR yet. I’m finishing the tests for #7026

@dosubot dosubot bot added size:XL This PR changes 500-999 lines, ignoring generated files. and removed size:M This PR changes 30-99 lines, ignoring generated files. labels Mar 18, 2025
@github-actions github-actions bot added enhancement New feature or request and removed enhancement New feature or request labels Mar 18, 2025
@edwinjosechittilappilly
Copy link
Collaborator

Working on Deprecating the old component and making this as a the new component.

@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. and removed size:XL This PR changes 500-999 lines, ignoring generated files. labels Mar 24, 2025
@github-actions github-actions bot added enhancement New feature or request and removed enhancement New feature or request labels Mar 24, 2025
@github-actions github-actions bot removed the enhancement New feature or request label Mar 25, 2025
@github-actions github-actions bot added enhancement New feature or request and removed enhancement New feature or request labels Mar 25, 2025
@github-actions github-actions bot added the enhancement New feature or request label Mar 25, 2025
@github-actions github-actions bot removed the enhancement New feature or request label Mar 25, 2025
@github-actions github-actions bot added the enhancement New feature or request label Mar 25, 2025
@github-actions github-actions bot added enhancement New feature or request and removed enhancement New feature or request labels Mar 25, 2025
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR refactors the looping functionality by introducing a new BasicLoopComponent that supports both Data and DataFrame types for inputs and adjusts output behavior accordingly. Key changes include:

  • Creating BasicLoopComponent with updated input validation and output methods.
  • Updating related methods and tests to use BasicLoopComponent instead of the legacy LoopComponent.
  • Adjusting import and type usages in test files and associated modules.

Reviewed Changes

Copilot reviewed 19 out of 19 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/backend/base/langflow/components/logic/loop_basic.py New BasicLoopComponent with updated input handling and output methods.
src/backend/base/langflow/graph/vertex/base.py Enhanced get_value_from_output_names with improved documentation and edge handling.
src/backend/base/langflow/custom/custom_component/component.py Added get_loop_output_value to support loop outputs.
src/backend/tests/unit/components/logic/test_loop.py Updated to test using BasicLoopComponent.
Other test and module files Minor updates to imports and dependencies supporting the new component changes.

Comment on lines +61 to +62
return current_index > data_length

Copy link
Preview

Copilot AI Mar 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using '>= data_length' instead of '> data_length' so that the loop terminates correctly when the current index equals the length of the data list.

Suggested change
return current_index > data_length
return current_index >= data_length

Copilot is powered by AI, so mistakes are possible. Review output carefully before use.

Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
@github-actions github-actions bot added enhancement New feature or request and removed enhancement New feature or request labels Mar 25, 2025
@github-actions github-actions bot added enhancement New feature or request and removed enhancement New feature or request labels Mar 26, 2025
@edwinjosechittilappilly edwinjosechittilappilly changed the title feat: QoL of Loop component feat: Dataframe Support Loop component, fixes loop input error Mar 26, 2025
@edwinjosechittilappilly edwinjosechittilappilly changed the title feat: Dataframe Support Loop component, fixes loop input error feat: add dataframe to Loop component, fixes loop input error Mar 26, 2025
@github-actions github-actions bot added enhancement New feature or request and removed enhancement New feature or request labels Mar 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request size:XL This PR changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants