Skip to content

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.

fix: unwrap narwhals type from mo.ui.table() (#2794)

Myles Scolnickcb9a8d889344
diff --git a/marimo/_plugins/ui/_impl/table.py b/marimo/_plugins/ui/_impl/table.py
index 93e12c8882..28de7066fd 100644
--- a/marimo/_plugins/ui/_impl/table.py
+++ b/marimo/_plugins/ui/_impl/table.py
@@ -416,7 +416,7 @@ class table(UIElement[List[str], Union[List[JSONType], IntoDataFrame]]):
indices = [int(v) for v in value]
self._selected_manager = self._searched_manager.select_rows(indices)
self._has_any_selection = len(indices) > 0
- return self._selected_manager.data # type: ignore[no-any-return]
+ return unwrap_narwhals_dataframe(self._selected_manager.data) # type: ignore[no-any-return]
def download_as(self, args: DownloadAsArgs) -> str:
# download selected rows if there are any, otherwise use all rows
diff --git a/tests/_plugins/ui/_impl/test_table.py b/tests/_plugins/ui/_impl/test_table.py
index 4eeb8e59a7..154519c876 100644
--- a/tests/_plugins/ui/_impl/test_table.py
+++ b/tests/_plugins/ui/_impl/test_table.py
@@ -270,7 +270,9 @@ def test_value_with_sorting_then_selection_dfs(df: Any) -> None:
page_number=0,
)
)
- assert nw.from_native(table._convert_value(["0"]))["a"][0] == "z"
+ value = table._convert_value(["0"])
+ assert not isinstance(value, nw.DataFrame)
+ assert nw.from_native(value)["a"][0] == "z"
table.search(
SearchTableArgs(
@@ -279,7 +281,9 @@ def test_value_with_sorting_then_selection_dfs(df: Any) -> None:
page_number=0,
)
)
- assert nw.from_native(table._convert_value(["0"]))["a"][0] == "x"
+ value = table._convert_value(["0"])
+ assert not isinstance(value, nw.DataFrame)
+ assert nw.from_native(value)["a"][0] == "x"
def test_value_with_search_then_selection() -> None:
@@ -335,7 +339,9 @@ def test_value_with_search_then_selection_dfs(df: Any) -> None:
page_number=0,
)
)
- assert nw.from_native(table._convert_value(["0"]))["a"][0] == "bar"
+ value = table._convert_value(["0"])
+ assert not isinstance(value, nw.DataFrame)
+ assert nw.from_native(value)["a"][0] == "bar"
table.search(
SearchTableArgs(
@@ -344,7 +350,9 @@ def test_value_with_search_then_selection_dfs(df: Any) -> None:
page_number=0,
)
)
- assert nw.from_native(table._convert_value(["0"]))["a"][0] == "foo"
+ value = table._convert_value(["0"])
+ assert not isinstance(value, nw.DataFrame)
+ assert nw.from_native(value)["a"][0] == "foo"
# empty search
table.search(
@@ -353,7 +361,9 @@ def test_value_with_search_then_selection_dfs(df: Any) -> None:
page_number=0,
)
)
- assert nw.from_native(table._convert_value(["2"]))["a"][0] == "baz"
+ value = table._convert_value(["2"])
+ assert not isinstance(value, nw.DataFrame)
+ assert nw.from_native(value)["a"][0] == "baz"
def test_table_with_too_many_columns_passes() -> None: