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: data-frame convert value (#204)

Myles Scolnick5db68ccf24d4
diff --git a/marimo/_plugins/ui/_impl/table.py b/marimo/_plugins/ui/_impl/table.py
index 3c43a40e18..7fa59754d2 100644
--- a/marimo/_plugins/ui/_impl/table.py
+++ b/marimo/_plugins/ui/_impl/table.py
@@ -36,7 +36,7 @@ TableData = Union[
@mddoc
-class table(UIElement[List[str], List[object]]):
+class table(UIElement[List[str], Union[List[object], "pd.DataFrame"]]):
"""
A table component.
@@ -96,7 +96,9 @@ class table(UIElement[List[str], List[object]]):
selection: Optional[Literal["single", "multi"]] = "multi",
*,
label: str = "",
- on_change: Optional[Callable[[List[object]], None]] = None,
+ on_change: Optional[
+ Callable[[Union[List[object], "pd.DataFrame"]], None]
+ ] = None,
) -> None:
self._data = data
normalized_data = _normalize_data(data)
@@ -123,7 +125,14 @@ class table(UIElement[List[str], List[object]]):
) -> TableData:
return self._data
- def _convert_value(self, value: list[str]) -> list[object]:
+ def _convert_value(
+ self, value: list[str]
+ ) -> Union[List[object], "pd.DataFrame"]:
+ if DependencyManager.has_pandas():
+ import pandas as pd
+
+ if isinstance(self._data, pd.DataFrame):
+ return self._data.iloc[[int(v) for v in value]]
return [self._data[int(v)] for v in value]