Skip to content

feat: add drop duplicates operation to DataFrameOperationsComponent#8665

Merged
edwinjosechittilappilly merged 5 commits into
mainfrom
fix-Df-operations
Jun 24, 2025
Merged

feat: add drop duplicates operation to DataFrameOperationsComponent#8665
edwinjosechittilappilly merged 5 commits into
mainfrom
fix-Df-operations

Conversation

@edwinjosechittilappilly
Copy link
Copy Markdown
Collaborator

@edwinjosechittilappilly edwinjosechittilappilly commented Jun 22, 2025

Summary by CodeRabbit

  • New Features
    • Added a "Drop Duplicates" option to DataFrame operations, allowing users to remove duplicate rows based on a specified column.
  • Improvements
    • The interface now dynamically displays the relevant input field when "Drop Duplicates" is selected.

@dosubot dosubot Bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Jun 22, 2025
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jun 22, 2025

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

A new "Drop Duplicates" operation was added to the DataFrameOperationsComponent, including UI configuration and operation handling. The perform_operation method and related logic were updated to support this operation, and a dedicated drop_duplicates method was introduced. Minor refactoring and logging enhancements were also applied.

Changes

File(s) Change Summary
.../dataframe_operations.py Added "Drop Duplicates" operation, updated UI config, implemented drop_duplicates method, refactored code, and improved logging.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant DataFrameOperationsComponent
    participant Logger

    User->>DataFrameOperationsComponent: Selects "Drop Duplicates" operation
    DataFrameOperationsComponent->>DataFrameOperationsComponent: update_build_config (show column_name input)
    User->>DataFrameOperationsComponent: Triggers perform_operation
    DataFrameOperationsComponent->>DataFrameOperationsComponent: Checks selected operation
    alt Operation is "Drop Duplicates"
        DataFrameOperationsComponent->>DataFrameOperationsComponent: drop_duplicates(df)
        DataFrameOperationsComponent-->>User: Returns DataFrame with duplicates dropped
    else Unsupported operation
        DataFrameOperationsComponent->>Logger: Log error
        DataFrameOperationsComponent-->>User: Raises ValueError
    end
Loading
✨ Finishing Touches
🧪 Generate Unit Tests
  • Create PR with Unit Tests
  • Post Copyable Unit Tests in Comment
  • Commit Unit Tests in branch fix-Df-operations

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai auto-generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@coderabbitai coderabbitai Bot changed the title @coderabbitai feat: add drop duplicates operation to DataFrameOperationsComponent Jun 22, 2025
@github-actions github-actions Bot added the enhancement New feature or request label Jun 22, 2025
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
src/backend/base/langflow/components/processing/dataframe_operations.py (1)

224-225: Consider enhancing for multiple column support.

The implementation is correct for single-column deduplication. Consider enhancing it to support multiple columns, as pandas drop_duplicates() can accept a list of column names.

Potential enhancement:

 def drop_duplicates(self, df: DataFrame) -> DataFrame:
-    return DataFrame(df.drop_duplicates(subset=self.column_name))
+    # Handle both single column (string) and multiple columns (list)
+    subset = self.column_name if isinstance(self.column_name, str) else self.column_name
+    return DataFrame(df.drop_duplicates(subset=subset))

This would allow future expansion to support multiple column selection in the UI.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 15f4451 and 51117e3.

📒 Files selected for processing (1)
  • src/backend/base/langflow/components/processing/dataframe_operations.py (4 hunks)
🧰 Additional context used
🪛 Ruff (0.11.9)
src/backend/base/langflow/components/processing/dataframe_operations.py

167-167: Avoid using the generic variable name df for DataFrames

(PD901)

🪛 GitHub Check: Ruff Style Check (3.13)
src/backend/base/langflow/components/processing/dataframe_operations.py

[failure] 167-167: Ruff (PD901)
src/backend/base/langflow/components/processing/dataframe_operations.py:167:9: PD901 Avoid using the generic variable name df for DataFrames

🪛 Pylint (3.3.7)
src/backend/base/langflow/components/processing/dataframe_operations.py

[refactor] 166-166: Too many return statements (10/6)

(R0911)

🪛 GitHub Actions: Ruff Style Check
src/backend/base/langflow/components/processing/dataframe_operations.py

[error] 167-167: PD901 Avoid using the generic variable name df for DataFrames.

🔇 Additional comments (5)
src/backend/base/langflow/components/processing/dataframe_operations.py (5)

2-10: LGTM! Clean import formatting.

The import statement formatting improves readability and maintainability.


11-11: Good addition for improved error handling.

Adding the logger import supports better error reporting in the perform_operation method.


19-19: Explicit component naming improves clarity.

Adding the explicit name attribute enhances component identification and debugging.


31-31: New operation choice properly integrated.

The "Drop Duplicates" operation is correctly added to the available choices.


161-162: UI configuration correctly implemented.

The dynamic field configuration for "Drop Duplicates" follows the established pattern and properly shows the column_name field.

Comment on lines +167 to 192
df = self.df.copy()
op = self.operation

if op == "Filter":
return self.filter_rows_by_value(df)
if op == "Sort":
return self.sort_by_column(df)
if op == "Drop Column":
return self.drop_column(df)
if op == "Rename Column":
return self.rename_column(df)
if op == "Add Column":
return self.add_column(df)
if op == "Select Columns":
return self.select_columns(df)
if op == "Head":
return self.head(df)
if op == "Tail":
return self.tail(df)
if op == "Replace Value":
return self.replace_values(df)
if op == "Drop Duplicates":
return self.drop_duplicates(df)
msg = f"Unsupported operation: {op}"
logger.error(msg)
raise ValueError(msg)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Address static analysis issues in method refactoring.

While the refactoring adds good error logging and the new operation handling, there are two issues to address:

  1. Variable naming: The generic variable name df violates pandas best practices (PD901). Consider using a more descriptive name like dataframe_copy or data_frame.

  2. Method complexity: The method now has 10 return statements, exceeding the recommended threshold of 6. Consider refactoring using a dispatch pattern.

Apply this diff to fix the variable naming issue:

-    df = self.df.copy()
+    dataframe_copy = self.df.copy()
     op = self.operation

-    if op == "Filter":
-        return self.filter_rows_by_value(df)
+    if op == "Filter":
+        return self.filter_rows_by_value(dataframe_copy)

And similarly update all other method calls to use dataframe_copy instead of df.

For the complexity issue, consider implementing a dispatch pattern:

+    operation_map = {
+        "Filter": self.filter_rows_by_value,
+        "Sort": self.sort_by_column,
+        "Drop Column": self.drop_column,
+        # ... etc
+    }
+    
+    if op in operation_map:
+        return operation_map[op](dataframe_copy)

Committable suggestion skipped: line range outside the PR's diff.

🧰 Tools
🪛 Ruff (0.11.9)

167-167: Avoid using the generic variable name df for DataFrames

(PD901)

🪛 GitHub Check: Ruff Style Check (3.13)

[failure] 167-167: Ruff (PD901)
src/backend/base/langflow/components/processing/dataframe_operations.py:167:9: PD901 Avoid using the generic variable name df for DataFrames

🪛 GitHub Actions: Ruff Style Check

[error] 167-167: PD901 Avoid using the generic variable name df for DataFrames.

🤖 Prompt for AI Agents
In src/backend/base/langflow/components/processing/dataframe_operations.py
around lines 167 to 192, rename the variable 'df' to a more descriptive name
like 'dataframe_copy' and update all method calls accordingly to follow pandas
best practices. To reduce method complexity caused by multiple return
statements, refactor the code to use a dispatch pattern by creating a dictionary
that maps operation names to their corresponding methods, then call the
appropriate method via this dictionary, ensuring only one return statement is
used.

@github-actions github-actions Bot added the lgtm This PR has been approved by a maintainer label Jun 23, 2025
Copy link
Copy Markdown
Member

@Cristhianzl Cristhianzl left a comment

Choose a reason for hiding this comment

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

image

@edwinjosechittilappilly
can we make the required fields to run the component as required?
otherwise the component will fail when running it.

Error building Component DataFrame Operations: Index([''], dtype='object')

image

@github-actions github-actions Bot removed the lgtm This PR has been approved by a maintainer label Jun 23, 2025
@github-actions github-actions Bot added enhancement New feature or request and removed enhancement New feature or request labels Jun 24, 2025
@github-actions github-actions Bot added enhancement New feature or request and removed enhancement New feature or request labels Jun 24, 2025
@github-actions github-actions Bot added enhancement New feature or request and removed enhancement New feature or request labels Jun 24, 2025
Copy link
Copy Markdown
Member

@Cristhianzl Cristhianzl left a comment

Choose a reason for hiding this comment

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

lgtm

@dosubot dosubot Bot added the lgtm This PR has been approved by a maintainer label Jun 24, 2025
@edwinjosechittilappilly edwinjosechittilappilly added this pull request to the merge queue Jun 24, 2025
Merged via the queue into main with commit 25746e2 Jun 24, 2025
72 of 74 checks passed
@edwinjosechittilappilly edwinjosechittilappilly deleted the fix-Df-operations branch June 24, 2025 23:18
Khurdhula-Harshavardhan pushed a commit to JigsawStack/langflow that referenced this pull request Jul 1, 2025
…angflow-ai#8665)

* Update dataframe_operations.py

* [autofix.ci] apply automated fixes

* Update dataframe_operations.py

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request lgtm This PR has been approved by a maintainer size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants