A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.
Python artificial-intelligencedagdata-sciencedata-visualizationdataflowdeveloper-toolsmachine-learningnotebookspipelinepythonreactivesqlweb-app
fix: sort only when column exists (#3031)
Shahmir Varqhaa55d7787b74a
diff --git a/marimo/_plugins/ui/_impl/dataframes/dataframe.py b/marimo/_plugins/ui/_impl/dataframes/dataframe.pyindex e9c4b8d1f3..6e49881b34 100644--- a/marimo/_plugins/ui/_impl/dataframes/dataframe.py+++ b/marimo/_plugins/ui/_impl/dataframes/dataframe.py@@ -268,7 +268,7 @@ class dataframe(UIElement[Dict[str, Any], DataFrameType]):if query:result = result.search(query)- if sort:+ if sort and sort.by in result.get_column_names():result = result.sort_values(sort.by, sort.descending)return resultdiff --git a/marimo/_plugins/ui/_impl/table.py b/marimo/_plugins/ui/_impl/table.pyindex 8c2dee6f8b..2885884bf8 100644--- a/marimo/_plugins/ui/_impl/table.py+++ b/marimo/_plugins/ui/_impl/table.py@@ -547,7 +547,7 @@ class table(UIElement[List[str], Union[List[JSONType], IntoDataFrame]]):if query:result = result.search(query)- if sort:+ if sort and sort.by in result.get_column_names():result = result.sort_values(sort.by, sort.descending)return resultdiff --git a/tests/_plugins/ui/_impl/test_table.py b/tests/_plugins/ui/_impl/test_table.pyindex ecca88b18c..3325730566 100644--- a/tests/_plugins/ui/_impl/test_table.py+++ b/tests/_plugins/ui/_impl/test_table.py@@ -366,6 +366,22 @@ def test_value_with_search_then_selection_dfs(df: Any) -> None:assert nw.from_native(value)["a"][0] == "baz"+def test_search_sort_nonexistent_columns() -> None:+ data = ["banana", "apple", "cherry", "date", "elderberry"]+ table = ui.table(data)++ # no error raised+ table.search(+ SearchTableArgs(+ sort=SortArgs("missing_column", descending=False),+ page_size=10,+ page_number=0,+ )+ )++ assert table._convert_value(["0"]) == ["banana"]++def test_table_with_too_many_columns_passes() -> None:data = {str(i): [1] for i in range(101)}assert ui.table(data) is not None