-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add default value support for table columns (#4043)
* Add 'type', 'description', and 'default' fields to Table schema and enhance formatter validation * Add type-based mapping to formatter validator in table schema * Add default value support for new table rows in TableNodeComponent * Add optional 'description' and 'default' fields to ColumnField interface * Add default value inference for table columns in utils.ts - Initialize 'default' property for table columns to null. - Infer default value from the first row of data if available. - Adjust column formatter determination based on sample value. * Add default table input validation and update formatter logic in Column model * Add unit tests for Column class in table schema module --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
- Loading branch information
1 parent
90b2c9d
commit 6515337
Showing
5 changed files
with
101 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# Generated by qodo Gen | ||
|
||
import pytest | ||
|
||
from langflow.schema.table import Column, FormatterType | ||
|
||
|
||
@pytest.fixture | ||
def client(): | ||
pass | ||
|
||
|
||
class TestColumn: | ||
# Creating a Column instance without display_name sets it to the name | ||
def test_create_column_without_display_name(self): | ||
column = Column(name="test_column") | ||
assert column.display_name == "test_column" | ||
|
||
# Creating a Column instance with valid formatter values | ||
def test_create_column_with_valid_formatter(self): | ||
column = Column(display_name="Test Column", name="test_column", formatter="date") | ||
assert column.formatter == FormatterType.date | ||
|
||
# Formatter is set based on provided formatter value | ||
def test_formatter_set_based_on_value(self): | ||
column = Column(display_name="Test Column", name="test_column", formatter="int") | ||
assert column.formatter == FormatterType.number | ||
|
||
# Default values for sortable and filterable are set to True | ||
def test_default_sortable_filterable(self): | ||
column = Column(display_name="Test Column", name="test_column") | ||
assert column.sortable is True | ||
assert column.filterable is True | ||
|
||
# Ensure formatter field is correctly set when provided a FormatterType | ||
def test_formatter_explicitly_set_to_enum(self): | ||
column = Column(display_name="Date Column", name="date_column", formatter=FormatterType.date) | ||
assert column.formatter == FormatterType.date | ||
|
||
# Invalid formatter raises ValueError | ||
def test_invalid_formatter_raises_value_error(self): | ||
with pytest.raises(ValueError): | ||
Column(display_name="Invalid Column", name="invalid_column", formatter="invalid") | ||
|
||
# Formatter is None when not provided | ||
def test_formatter_none_when_not_provided(self): | ||
column = Column(display_name="Test Column", name="test_column") | ||
assert column.formatter is None | ||
|
||
# Description and default can be set | ||
def test_description_and_default(self): | ||
column = Column( | ||
display_name="Test Column", name="test_column", description="A test column", default="default_value" | ||
) | ||
assert column.description == "A test column" | ||
assert column.default == "default_value" | ||
|
||
def test_create_with_type_instead_of_formatter(self): | ||
column = Column(display_name="Test Column", name="test_column", type="date") | ||
assert column.formatter == FormatterType.date |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters