feat: enhance DataFrame Operations component with contains filter and modern UI#8838
Conversation
… modern UI - Add "contains" filter operator for partial string matching in DataFrame filters - Update UI to use SortableListInput with icons for consistent modern design - Add 7 filter operators: equals, not equals, contains, starts with, ends with, greater than, less than - Fix deselection handling to prevent "unhashable type: list" errors - Improve dynamic field visibility when operations are deselected - Add comprehensive test suite with 25 tests covering all operations and edge cases - Update placeholder text from "Select DataFrame Operation" to "Select Operation" 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
|
Important Review skippedAuto incremental reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the WalkthroughThe DataFrame operations component was updated to use a sortable list input for selecting operations, allowing richer metadata and icons per operation. Filtering now supports multiple operators, and dynamic UI logic was revised accordingly. The test suite was comprehensively rewritten to cover all new behaviors, edge cases, and UI dynamics. Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant UI
participant DataFrameOperationsComponent
participant Pandas
User->>UI: Selects DataFrame operation (SortableListInput)
UI->>DataFrameOperationsComponent: Sends selected operation and parameters
DataFrameOperationsComponent->>DataFrameOperationsComponent: update_build_config (show/hide fields)
DataFrameOperationsComponent->>Pandas: perform_operation (with selected operator/filter)
Pandas-->>DataFrameOperationsComponent: Returns modified DataFrame
DataFrameOperationsComponent-->>UI: Returns result
UI-->>User: Displays updated DataFrame
Possibly related PRs
Suggested labels
Suggested reviewers
✨ Finishing Touches🧪 Generate unit tests
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed 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)
Other keywords and placeholders
Documentation and Community
|
There was a problem hiding this comment.
Actionable comments posted: 1
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
src/backend/base/langflow/components/processing/dataframe_operations.py(6 hunks)src/backend/tests/unit/components/processing/test_dataframe_operations.py(1 hunks)
🧰 Additional context used
📓 Path-based instructions (8)
`src/backend/base/langflow/components/**/*.py`: Add new backend components to th...
src/backend/base/langflow/components/**/*.py: Add new backend components to the appropriate subdirectory under src/backend/base/langflow/components/
Implement async component methods using async def and await for asynchronous operations
Use asyncio.create_task for background work in async components and ensure proper cleanup on cancellation
Use asyncio.Queue for non-blocking queue operations in async components and handle timeouts appropriately
📄 Source: CodeRabbit Inference Engine (.cursor/rules/backend_development.mdc)
List of files the instruction was applied to:
src/backend/base/langflow/components/processing/dataframe_operations.py
`src/backend/**/*.py`: Run make format_backend to format Python code early and often Run make lint to check for linting issues in backend Python code
src/backend/**/*.py: Run make format_backend to format Python code early and often
Run make lint to check for linting issues in backend Python code
📄 Source: CodeRabbit Inference Engine (.cursor/rules/backend_development.mdc)
List of files the instruction was applied to:
src/backend/base/langflow/components/processing/dataframe_operations.pysrc/backend/tests/unit/components/processing/test_dataframe_operations.py
`src/backend/**/components/**/*.py`: In your Python component class, set the `icon` attribute to a string matching the frontend icon mapping exactly (case-sensitive).
src/backend/**/components/**/*.py: In your Python component class, set theiconattribute to a string matching the frontend icon mapping exactly (case-sensitive).
📄 Source: CodeRabbit Inference Engine (.cursor/rules/icons.mdc)
List of files the instruction was applied to:
src/backend/base/langflow/components/processing/dataframe_operations.pysrc/backend/tests/unit/components/processing/test_dataframe_operations.py
`src/backend/tests/unit/components/**/*.py`: Mirror the component directory stru...
src/backend/tests/unit/components/**/*.py: Mirror the component directory structure in unit tests under src/backend/tests/unit/components/
Use ComponentTestBaseWithClient or ComponentTestBaseWithoutClient as base classes for component unit tests
Provide file_names_mapping in tests for backward compatibility version testing
Create comprehensive unit tests for all new components
Use the client fixture from conftest.py for FastAPI API endpoint tests
Test authenticated FastAPI endpoints using logged_in_headers in tests
📄 Source: CodeRabbit Inference Engine (.cursor/rules/backend_development.mdc)
List of files the instruction was applied to:
src/backend/tests/unit/components/processing/test_dataframe_operations.py
`src/backend/tests/unit/**/*.py`: Use in-memory SQLite for database tests Test c...
src/backend/tests/unit/**/*.py: Use in-memory SQLite for database tests
Test component integration within flows using create_flow, build_flow, and get_build_events utilities
Use pytest.mark.api_key_required and pytest.mark.no_blockbuster for tests involving external APIs
📄 Source: CodeRabbit Inference Engine (.cursor/rules/backend_development.mdc)
List of files the instruction was applied to:
src/backend/tests/unit/components/processing/test_dataframe_operations.py
`src/backend/tests/**/*.py`: Unit tests for backend code should be located in 's...
src/backend/tests/**/*.py: Unit tests for backend code should be located in 'src/backend/tests/' and organized by component subdirectory for component tests.
Test files should use the same filename as the component with an appropriate test prefix or suffix (e.g., 'my_component.py' → 'test_my_component.py').
Use the 'client' fixture (an async httpx.AsyncClient) for API tests, as defined in 'src/backend/tests/conftest.py'.
Skip client creation in tests by marking them with '@pytest.mark.noclient' when the 'client' fixture is not needed.
Inherit from the appropriate ComponentTestBase class ('ComponentTestBase', 'ComponentTestBaseWithClient', or 'ComponentTestBaseWithoutClient') and provide the required fixtures: 'component_class', 'default_kwargs', and 'file_names_mapping' when adding a new component test.
📄 Source: CodeRabbit Inference Engine (.cursor/rules/testing.mdc)
List of files the instruction was applied to:
src/backend/tests/unit/components/processing/test_dataframe_operations.py
`{src/backend/tests/**/*.py,src/frontend/**/*.test.{ts,tsx,js,jsx},src/frontend/...
{src/backend/tests/**/*.py,src/frontend/**/*.test.{ts,tsx,js,jsx},src/frontend/**/*.spec.{ts,tsx,js,jsx},tests/**/*.py}: Each test should have a clear docstring explaining its purpose.
Complex test setups should be commented, and mock usage should be documented within the test code.
Expected behaviors should be explicitly stated in test docstrings or comments.
Create comprehensive unit tests for all new components.
Test both sync and async code paths in components.
Mock external dependencies appropriately in tests.
Test error handling and edge cases in components.
Validate input/output behavior in tests.
Test component initialization and configuration.
📄 Source: CodeRabbit Inference Engine (.cursor/rules/testing.mdc)
List of files the instruction was applied to:
src/backend/tests/unit/components/processing/test_dataframe_operations.py
`{src/backend/tests/**/*.py,tests/**/*.py}`: Use '@pytest.mark.asyncio' for asyn...
{src/backend/tests/**/*.py,tests/**/*.py}: Use '@pytest.mark.asyncio' for async test functions.
Test queue operations in async tests using 'asyncio.Queue' and non-blocking put/get methods.
Use the 'no_blockbuster' pytest marker to skip the blockbuster plugin in tests.
Be aware of ContextVar propagation in async tests and test both direct event loop execution and 'asyncio.to_thread' scenarios.
Each test should ensure proper resource cleanup, especially in async fixtures using 'try/finally' and cleanup methods.
Test that operations respect timeout constraints and assert elapsed time is within tolerance.
Test Langflow's 'Message' objects and chat functionality by asserting correct properties and structure.
Use predefined JSON flows and utility functions for flow testing (e.g., 'create_flow', 'build_flow', 'get_build_events', 'consume_and_assert_stream').
Test components that need external APIs with proper pytest markers such as '@pytest.mark.api_key_required' and '@pytest.mark.no_blockbuster'.
Use 'MockLanguageModel' for testing language model components without external API calls.
Use 'anyio' and 'aiofiles' for async file operations in tests.
Test Langflow's REST API endpoints using the async 'client' fixture and assert correct status codes and response structure.
Test component configuration updates by asserting changes in build config dictionaries.
Test real-time event streaming endpoints by consuming NDJSON event streams and validating event structure.
Test backward compatibility across Langflow versions by mapping component files to supported versions using 'VersionComponentMapping'.
Test webhook endpoints by posting payloads and asserting correct processing and status codes.
Test error handling by monkeypatching internal functions to raise exceptions and asserting correct error responses.
📄 Source: CodeRabbit Inference Engine (.cursor/rules/testing.mdc)
List of files the instruction was applied to:
src/backend/tests/unit/components/processing/test_dataframe_operations.py
🧠 Learnings (2)
src/backend/base/langflow/components/processing/dataframe_operations.py (1)
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/backend_development.mdc:0-0
Timestamp: 2025-06-30T14:39:17.428Z
Learning: Applies to src/backend/base/langflow/components/**/__init__.py : Update __init__.py with alphabetical imports when adding new components
src/backend/tests/unit/components/processing/test_dataframe_operations.py (12)
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/backend_development.mdc:0-0
Timestamp: 2025-06-30T14:39:17.428Z
Learning: Applies to src/backend/tests/unit/components/**/*.py : Create comprehensive unit tests for all new components
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/backend_development.mdc:0-0
Timestamp: 2025-06-30T14:39:17.428Z
Learning: Applies to src/backend/tests/unit/components/**/*.py : Mirror the component directory structure in unit tests under src/backend/tests/unit/components/
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/testing.mdc:0-0
Timestamp: 2025-06-30T14:41:58.837Z
Learning: Applies to {src/backend/tests/**/*.py,src/frontend/**/*.test.{ts,tsx,js,jsx},src/frontend/**/*.spec.{ts,tsx,js,jsx},tests/**/*.py} : Create comprehensive unit tests for all new components.
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/testing.mdc:0-0
Timestamp: 2025-06-30T14:41:58.837Z
Learning: Applies to src/backend/tests/**/*.py : Inherit from the appropriate ComponentTestBase class ('ComponentTestBase', 'ComponentTestBaseWithClient', or 'ComponentTestBaseWithoutClient') and provide the required fixtures: 'component_class', 'default_kwargs', and 'file_names_mapping' when adding a new component test.
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/backend_development.mdc:0-0
Timestamp: 2025-06-30T14:39:17.428Z
Learning: Applies to src/backend/tests/unit/**/*.py : Test component integration within flows using create_flow, build_flow, and get_build_events utilities
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/testing.mdc:0-0
Timestamp: 2025-06-30T14:41:58.837Z
Learning: Applies to {src/backend/tests/**/*.py,tests/**/*.py} : Test component configuration updates by asserting changes in build config dictionaries.
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/testing.mdc:0-0
Timestamp: 2025-06-30T14:41:58.837Z
Learning: Applies to src/backend/tests/**/*.py : Unit tests for backend code should be located in 'src/backend/tests/' and organized by component subdirectory for component tests.
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/testing.mdc:0-0
Timestamp: 2025-06-30T14:41:58.837Z
Learning: Applies to {src/backend/tests/**/*.py,tests/**/*.py} : Test backward compatibility across Langflow versions by mapping component files to supported versions using 'VersionComponentMapping'.
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/testing.mdc:0-0
Timestamp: 2025-06-30T14:41:58.837Z
Learning: Applies to {src/backend/tests/**/*.py,src/frontend/**/*.test.{ts,tsx,js,jsx},src/frontend/**/*.spec.{ts,tsx,js,jsx},tests/**/*.py} : Complex test setups should be commented, and mock usage should be documented within the test code.
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/testing.mdc:0-0
Timestamp: 2025-06-30T14:41:58.837Z
Learning: Applies to src/backend/tests/**/*.py : Test files should use the same filename as the component with an appropriate test prefix or suffix (e.g., 'my_component.py' → 'test_my_component.py').
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/testing.mdc:0-0
Timestamp: 2025-06-30T14:41:58.837Z
Learning: Applies to {src/backend/tests/**/*.py,src/frontend/**/*.test.{ts,tsx,js,jsx},src/frontend/**/*.spec.{ts,tsx,js,jsx},tests/**/*.py} : Test error handling and edge cases in components.
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/testing.mdc:0-0
Timestamp: 2025-06-30T14:41:58.837Z
Learning: Applies to {src/backend/tests/**/*.py,src/frontend/**/*.test.{ts,tsx,js,jsx},src/frontend/**/*.spec.{ts,tsx,js,jsx},tests/**/*.py} : Validate input/output behavior in tests.
🪛 GitHub Check: Ruff Style Check (3.13)
src/backend/base/langflow/components/processing/dataframe_operations.py
[failure] 169-173: Ruff (SIM108)
src/backend/base/langflow/components/processing/dataframe_operations.py:169:17: SIM108 Use ternary operator operation_name = field_value[0].get("name", "") if len(field_value) > 0 else "" instead of if-else-block
🪛 Ruff (0.11.9)
src/backend/base/langflow/components/processing/dataframe_operations.py
169-173: Use ternary operator operation_name = field_value[0].get("name", "") if len(field_value) > 0 else "" instead of if-else-block
(SIM108)
🪛 GitHub Actions: Ruff Style Check
src/backend/base/langflow/components/processing/dataframe_operations.py
[error] 169-169: Ruff SIM108: Use ternary operator operation_name = field_value[0].get("name", "") if len(field_value) > 0 else "" instead of if-else-block.
🔇 Additional comments (8)
src/backend/base/langflow/components/processing/dataframe_operations.py (4)
44-63: LGTM! Nice UI modernization.The migration to
SortableListInputwith icons enhances the user experience while maintaining single-selection behavior throughlimit=1. The icon choices are intuitive for each operation.
78-87: Excellent addition of filter operators.The comprehensive set of filter operators enables powerful DataFrame filtering capabilities. Setting the default to "equals" ensures backward compatibility for existing workflows.
212-222: Good handling of the new input format.The implementation correctly extracts the operation from the
SortableListInputformat and gracefully handles empty selections by returning the original DataFrame unchanged.
248-283: Excellent implementation of comprehensive filter operators!The enhanced filtering logic is well-designed with:
- Smart numeric conversion that falls back to string comparison
- Proper handling of missing values using
na=Falsein string operations- Robust error handling for type mismatches
- Consistent behavior across all operators
This is a significant improvement to the component's functionality.
src/backend/tests/unit/components/processing/test_dataframe_operations.py (4)
7-24: Well-structured test fixtures.The sample DataFrame provides realistic test data with good variety in data types and values, which is essential for testing all the filter operators effectively.
115-208: Comprehensive filter operator test coverage!Excellent test suite for all filter operators with well-chosen test data and thorough assertions. The special callout for the "contains" filter appropriately highlights the PR's main feature.
210-265: Excellent edge case coverage.The tests thoroughly cover important edge cases including empty selections, invalid formats, and error conditions. Using
pytest.raisesfor the KeyError test is the correct approach.
389-423: Well-designed integration test.The comprehensive test of all filter operators on a single dataset provides excellent verification that all operators work correctly. The parameterized test cases with clear failure messages make debugging easy.
| if field_name == "operation": | ||
| if field_value == "Filter": | ||
| # Handle SortableListInput format | ||
| if isinstance(field_value, list): | ||
| if len(field_value) > 0: | ||
| operation_name = field_value[0].get("name", "") | ||
| else: | ||
| # Handle empty selection (user deselected) | ||
| operation_name = "" | ||
| else: | ||
| operation_name = field_value or "" | ||
|
|
||
| # If no operation selected, all dynamic fields stay hidden (already set to False above) | ||
| if not operation_name: | ||
| return build_config | ||
|
|
There was a problem hiding this comment.
Apply the suggested style improvement to fix the pipeline failure.
The logic is correct, but the static analysis tool recommends using a ternary operator for better conciseness.
Apply this diff to resolve the Ruff style check failure:
- if isinstance(field_value, list):
- if len(field_value) > 0:
- operation_name = field_value[0].get("name", "")
- else:
- # Handle empty selection (user deselected)
- operation_name = ""
+ if isinstance(field_value, list):
+ operation_name = field_value[0].get("name", "") if len(field_value) > 0 else ""📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| if field_name == "operation": | |
| if field_value == "Filter": | |
| # Handle SortableListInput format | |
| if isinstance(field_value, list): | |
| if len(field_value) > 0: | |
| operation_name = field_value[0].get("name", "") | |
| else: | |
| # Handle empty selection (user deselected) | |
| operation_name = "" | |
| else: | |
| operation_name = field_value or "" | |
| # If no operation selected, all dynamic fields stay hidden (already set to False above) | |
| if not operation_name: | |
| return build_config | |
| if field_name == "operation": | |
| # Handle SortableListInput format | |
| if isinstance(field_value, list): | |
| operation_name = field_value[0].get("name", "") if len(field_value) > 0 else "" | |
| else: | |
| operation_name = field_value or "" | |
| # If no operation selected, all dynamic fields stay hidden (already set to False above) | |
| if not operation_name: | |
| return build_config |
🧰 Tools
🪛 GitHub Check: Ruff Style Check (3.13)
[failure] 169-173: Ruff (SIM108)
src/backend/base/langflow/components/processing/dataframe_operations.py:169:17: SIM108 Use ternary operator operation_name = field_value[0].get("name", "") if len(field_value) > 0 else "" instead of if-else-block
🪛 Ruff (0.11.9)
169-173: Use ternary operator operation_name = field_value[0].get("name", "") if len(field_value) > 0 else "" instead of if-else-block
(SIM108)
🪛 GitHub Actions: Ruff Style Check
[error] 169-169: Ruff SIM108: Use ternary operator operation_name = field_value[0].get("name", "") if len(field_value) > 0 else "" instead of if-else-block.
🤖 Prompt for AI Agents
In src/backend/base/langflow/components/processing/dataframe_operations.py
around lines 166 to 180, replace the multi-line if-else block that assigns
operation_name based on field_value with a single-line ternary expression to
improve conciseness and fix the Ruff style check failure. Use a ternary operator
to assign operation_name to field_value[0].get("name", "") if field_value is a
non-empty list, otherwise assign an empty string or field_value or empty string
accordingly.
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
src/backend/base/langflow/components/processing/dataframe_operations.py (1)
168-173: Simplify operation name extraction with ternary operator.The logic is correct but can be simplified as suggested by static analysis.
- if isinstance(field_value, list): - if len(field_value) > 0: - operation_name = field_value[0].get("name", "") - else: - # Handle empty selection (user deselected) - operation_name = "" + if isinstance(field_value, list): + operation_name = field_value[0].get("name", "") if len(field_value) > 0 else ""
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
src/backend/base/langflow/components/processing/dataframe_operations.py(6 hunks)src/backend/tests/unit/components/processing/test_dataframe_operations.py(1 hunks)
🧰 Additional context used
📓 Path-based instructions (8)
`src/backend/base/langflow/components/**/*.py`: Add new backend components to th...
src/backend/base/langflow/components/**/*.py: Add new backend components to the appropriate subdirectory under src/backend/base/langflow/components/
Implement async component methods using async def and await for asynchronous operations
Use asyncio.create_task for background work in async components and ensure proper cleanup on cancellation
Use asyncio.Queue for non-blocking queue operations in async components and handle timeouts appropriately
📄 Source: CodeRabbit Inference Engine (.cursor/rules/backend_development.mdc)
List of files the instruction was applied to:
src/backend/base/langflow/components/processing/dataframe_operations.py
`src/backend/**/*.py`: Run make format_backend to format Python code early and often Run make lint to check for linting issues in backend Python code
src/backend/**/*.py: Run make format_backend to format Python code early and often
Run make lint to check for linting issues in backend Python code
📄 Source: CodeRabbit Inference Engine (.cursor/rules/backend_development.mdc)
List of files the instruction was applied to:
src/backend/base/langflow/components/processing/dataframe_operations.pysrc/backend/tests/unit/components/processing/test_dataframe_operations.py
`src/backend/**/components/**/*.py`: In your Python component class, set the `icon` attribute to a string matching the frontend icon mapping exactly (case-sensitive).
src/backend/**/components/**/*.py: In your Python component class, set theiconattribute to a string matching the frontend icon mapping exactly (case-sensitive).
📄 Source: CodeRabbit Inference Engine (.cursor/rules/icons.mdc)
List of files the instruction was applied to:
src/backend/base/langflow/components/processing/dataframe_operations.pysrc/backend/tests/unit/components/processing/test_dataframe_operations.py
`src/backend/tests/unit/components/**/*.py`: Mirror the component directory stru...
src/backend/tests/unit/components/**/*.py: Mirror the component directory structure in unit tests under src/backend/tests/unit/components/
Use ComponentTestBaseWithClient or ComponentTestBaseWithoutClient as base classes for component unit tests
Provide file_names_mapping in tests for backward compatibility version testing
Create comprehensive unit tests for all new components
Use the client fixture from conftest.py for FastAPI API endpoint tests
Test authenticated FastAPI endpoints using logged_in_headers in tests
📄 Source: CodeRabbit Inference Engine (.cursor/rules/backend_development.mdc)
List of files the instruction was applied to:
src/backend/tests/unit/components/processing/test_dataframe_operations.py
`src/backend/tests/unit/**/*.py`: Use in-memory SQLite for database tests Test c...
src/backend/tests/unit/**/*.py: Use in-memory SQLite for database tests
Test component integration within flows using create_flow, build_flow, and get_build_events utilities
Use pytest.mark.api_key_required and pytest.mark.no_blockbuster for tests involving external APIs
📄 Source: CodeRabbit Inference Engine (.cursor/rules/backend_development.mdc)
List of files the instruction was applied to:
src/backend/tests/unit/components/processing/test_dataframe_operations.py
`src/backend/tests/**/*.py`: Unit tests for backend code should be located in 's...
src/backend/tests/**/*.py: Unit tests for backend code should be located in 'src/backend/tests/' and organized by component subdirectory for component tests.
Test files should use the same filename as the component with an appropriate test prefix or suffix (e.g., 'my_component.py' → 'test_my_component.py').
Use the 'client' fixture (an async httpx.AsyncClient) for API tests, as defined in 'src/backend/tests/conftest.py'.
Skip client creation in tests by marking them with '@pytest.mark.noclient' when the 'client' fixture is not needed.
Inherit from the appropriate ComponentTestBase class ('ComponentTestBase', 'ComponentTestBaseWithClient', or 'ComponentTestBaseWithoutClient') and provide the required fixtures: 'component_class', 'default_kwargs', and 'file_names_mapping' when adding a new component test.
📄 Source: CodeRabbit Inference Engine (.cursor/rules/testing.mdc)
List of files the instruction was applied to:
src/backend/tests/unit/components/processing/test_dataframe_operations.py
`{src/backend/tests/**/*.py,src/frontend/**/*.test.{ts,tsx,js,jsx},src/frontend/...
{src/backend/tests/**/*.py,src/frontend/**/*.test.{ts,tsx,js,jsx},src/frontend/**/*.spec.{ts,tsx,js,jsx},tests/**/*.py}: Each test should have a clear docstring explaining its purpose.
Complex test setups should be commented, and mock usage should be documented within the test code.
Expected behaviors should be explicitly stated in test docstrings or comments.
Create comprehensive unit tests for all new components.
Test both sync and async code paths in components.
Mock external dependencies appropriately in tests.
Test error handling and edge cases in components.
Validate input/output behavior in tests.
Test component initialization and configuration.
📄 Source: CodeRabbit Inference Engine (.cursor/rules/testing.mdc)
List of files the instruction was applied to:
src/backend/tests/unit/components/processing/test_dataframe_operations.py
`{src/backend/tests/**/*.py,tests/**/*.py}`: Use '@pytest.mark.asyncio' for asyn...
{src/backend/tests/**/*.py,tests/**/*.py}: Use '@pytest.mark.asyncio' for async test functions.
Test queue operations in async tests using 'asyncio.Queue' and non-blocking put/get methods.
Use the 'no_blockbuster' pytest marker to skip the blockbuster plugin in tests.
Be aware of ContextVar propagation in async tests and test both direct event loop execution and 'asyncio.to_thread' scenarios.
Each test should ensure proper resource cleanup, especially in async fixtures using 'try/finally' and cleanup methods.
Test that operations respect timeout constraints and assert elapsed time is within tolerance.
Test Langflow's 'Message' objects and chat functionality by asserting correct properties and structure.
Use predefined JSON flows and utility functions for flow testing (e.g., 'create_flow', 'build_flow', 'get_build_events', 'consume_and_assert_stream').
Test components that need external APIs with proper pytest markers such as '@pytest.mark.api_key_required' and '@pytest.mark.no_blockbuster'.
Use 'MockLanguageModel' for testing language model components without external API calls.
Use 'anyio' and 'aiofiles' for async file operations in tests.
Test Langflow's REST API endpoints using the async 'client' fixture and assert correct status codes and response structure.
Test component configuration updates by asserting changes in build config dictionaries.
Test real-time event streaming endpoints by consuming NDJSON event streams and validating event structure.
Test backward compatibility across Langflow versions by mapping component files to supported versions using 'VersionComponentMapping'.
Test webhook endpoints by posting payloads and asserting correct processing and status codes.
Test error handling by monkeypatching internal functions to raise exceptions and asserting correct error responses.
📄 Source: CodeRabbit Inference Engine (.cursor/rules/testing.mdc)
List of files the instruction was applied to:
src/backend/tests/unit/components/processing/test_dataframe_operations.py
🧠 Learnings (2)
src/backend/base/langflow/components/processing/dataframe_operations.py (1)
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/backend_development.mdc:0-0
Timestamp: 2025-06-30T14:39:17.428Z
Learning: Applies to src/backend/base/langflow/components/**/__init__.py : Update __init__.py with alphabetical imports when adding new components
src/backend/tests/unit/components/processing/test_dataframe_operations.py (10)
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/backend_development.mdc:0-0
Timestamp: 2025-06-30T14:39:17.428Z
Learning: Applies to src/backend/tests/unit/components/**/*.py : Create comprehensive unit tests for all new components
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/testing.mdc:0-0
Timestamp: 2025-06-30T14:41:58.837Z
Learning: Applies to {src/backend/tests/**/*.py,src/frontend/**/*.test.{ts,tsx,js,jsx},src/frontend/**/*.spec.{ts,tsx,js,jsx},tests/**/*.py} : Create comprehensive unit tests for all new components.
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/backend_development.mdc:0-0
Timestamp: 2025-06-30T14:39:17.428Z
Learning: Applies to src/backend/tests/unit/components/**/*.py : Mirror the component directory structure in unit tests under src/backend/tests/unit/components/
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/backend_development.mdc:0-0
Timestamp: 2025-06-30T14:39:17.428Z
Learning: Applies to src/backend/tests/unit/**/*.py : Test component integration within flows using create_flow, build_flow, and get_build_events utilities
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/testing.mdc:0-0
Timestamp: 2025-06-30T14:41:58.837Z
Learning: Applies to src/backend/tests/**/*.py : Inherit from the appropriate ComponentTestBase class ('ComponentTestBase', 'ComponentTestBaseWithClient', or 'ComponentTestBaseWithoutClient') and provide the required fixtures: 'component_class', 'default_kwargs', and 'file_names_mapping' when adding a new component test.
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/testing.mdc:0-0
Timestamp: 2025-06-30T14:41:58.837Z
Learning: Applies to {src/backend/tests/**/*.py,tests/**/*.py} : Test backward compatibility across Langflow versions by mapping component files to supported versions using 'VersionComponentMapping'.
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/testing.mdc:0-0
Timestamp: 2025-06-30T14:41:58.837Z
Learning: Applies to src/backend/tests/**/*.py : Unit tests for backend code should be located in 'src/backend/tests/' and organized by component subdirectory for component tests.
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/testing.mdc:0-0
Timestamp: 2025-06-30T14:41:58.837Z
Learning: Applies to {src/backend/tests/**/*.py,tests/**/*.py} : Test component configuration updates by asserting changes in build config dictionaries.
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/testing.mdc:0-0
Timestamp: 2025-06-30T14:41:58.837Z
Learning: Applies to {src/backend/tests/**/*.py,src/frontend/**/*.test.{ts,tsx,js,jsx},src/frontend/**/*.spec.{ts,tsx,js,jsx},tests/**/*.py} : Test error handling and edge cases in components.
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/testing.mdc:0-0
Timestamp: 2025-06-30T14:41:58.837Z
Learning: Applies to {src/backend/tests/**/*.py,src/frontend/**/*.test.{ts,tsx,js,jsx},src/frontend/**/*.spec.{ts,tsx,js,jsx},tests/**/*.py} : Validate input/output behavior in tests.
🧬 Code Graph Analysis (1)
src/backend/base/langflow/components/processing/dataframe_operations.py (3)
src/backend/tests/unit/components/processing/test_dataframe_operations.py (1)
component(21-23)src/backend/base/langflow/inputs/inputs.py (2)
SortableListInput(535-545)DropdownInput(467-491)src/backend/base/langflow/schema/dataframe.py (1)
DataFrame(11-206)
🪛 GitHub Check: Ruff Style Check (3.13)
src/backend/base/langflow/components/processing/dataframe_operations.py
[failure] 169-173: Ruff (SIM108)
src/backend/base/langflow/components/processing/dataframe_operations.py:169:17: SIM108 Use ternary operator operation_name = field_value[0].get("name", "") if len(field_value) > 0 else "" instead of if-else-block
🪛 Ruff (0.11.9)
src/backend/base/langflow/components/processing/dataframe_operations.py
169-173: Use ternary operator operation_name = field_value[0].get("name", "") if len(field_value) > 0 else "" instead of if-else-block
(SIM108)
🪛 GitHub Actions: Ruff Style Check
src/backend/base/langflow/components/processing/dataframe_operations.py
[error] 169-169: Ruff SIM108: Use ternary operator operation_name = field_value[0].get("name", "") if len(field_value) > 0 else "" instead of if-else-block.
🔇 Additional comments (8)
src/backend/base/langflow/components/processing/dataframe_operations.py (4)
1-1: LGTM!The pandas import is necessary for the new filtering functionality that uses
pd.to_numeric.
44-63: UI modernization looks good!The change from
DropdownInputtoSortableListInputwith icon metadata aligns well with the PR objectives. Thelimit=1ensures single selection behavior is maintained.
212-221: Good defensive programming!The early return when no operation is selected properly handles the deselection case and prevents potential errors downstream.
247-283: Excellent implementation of the enhanced filtering functionality!The filter method now supports all the required operators with smart type conversion and proper edge case handling:
- Numeric comparisons attempt type conversion with fallback to string comparison
- String operations properly handle missing values with
na=False- The fallback to equals operator provides a safe default
This implementation fully addresses the PR objectives for the contains filter and other operators.
src/backend/tests/unit/components/processing/test_dataframe_operations.py (4)
7-24: Well-structured test fixtures!The fixtures provide comprehensive test data and proper component initialization. The sample DataFrame includes various data types (strings, numbers, emails) which enables thorough testing of all filter operators.
115-208: Excellent comprehensive test coverage for all filter operators!The test suite thoroughly covers all 7 filter operators mentioned in the PR objectives:
- equals, not equals
- contains (the main new feature)
- starts with, ends with
- greater than, less than
Each operator is tested with appropriate data and assertions verify the expected behavior.
210-265: Thorough edge case testing!The edge case tests properly verify the bug fixes mentioned in the PR objectives:
- Empty selection handling (fixes the "unhashable type: list" error)
- Proper error handling for non-existent columns
- Graceful handling of filters with no matches
This ensures the component is robust against various user inputs.
389-423: Excellent integration test!The comprehensive integration test verifies all filter operators work correctly together on the same dataset with clear test cases and expected results. This provides confidence that the implementation works end-to-end.
|
fixing ruff errors soon |
… modern UI (langflow-ai#8838) * feat: enhance DataFrame Operations component with contains filter and modern UI - Add "contains" filter operator for partial string matching in DataFrame filters - Update UI to use SortableListInput with icons for consistent modern design - Add 7 filter operators: equals, not equals, contains, starts with, ends with, greater than, less than - Fix deselection handling to prevent "unhashable type: list" errors - Improve dynamic field visibility when operations are deselected - Add comprehensive test suite with 25 tests covering all operations and edge cases - Update placeholder text from "Select DataFrame Operation" to "Select Operation" 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * [autofix.ci] apply automated fixes * Update dataframe_operations.py --------- Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: Edwin Jose <edwin.jose@datastax.com>
Summary
This PR enhances the DataFrame Operations component with several key improvements:
• "Contains" Filter: Added partial string matching capability for filtering DataFrame rows
• Modern UI: Updated to use SortableListInput with icons for consistent design with Data Operations component
• Extended Filter Operators: Now supports 7 operators (equals, not equals, contains, starts with, ends with, greater than, less than)
• Bug Fixes: Fixed deselection handling and dynamic field visibility issues
• Comprehensive Testing: Added 25 tests covering all operations and edge cases
Key Changes
🎯 New "Contains" Filter
🎨 Modern UI Consistency
SortableListInputwith iconsDropdownInputfor usability🐛 Bug Fixes
✅ Comprehensive Testing
Test Results
All tests pass, confirming the component works reliably with the new enhancements.
Test plan
🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Bug Fixes
Tests