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: nested dictionary table (#3774)
Myles Scolnick2e180141c569
diff --git a/frontend/src/components/data-table/columns.tsx b/frontend/src/components/data-table/columns.tsxindex 9f2103e455..dc052c57cc 100644--- a/frontend/src/components/data-table/columns.tsx+++ b/frontend/src/components/data-table/columns.tsx@@ -7,7 +7,7 @@ import {DataTableColumnHeaderWithSummary,} from "./column-header";import { Checkbox } from "../ui/checkbox";-import { MimeCell } from "./mime-cell";+import { isMimeValue, MimeCell } from "./mime-cell";import type { DataType } from "@/core/kernel/messages";import { TableColumnSummary } from "./column-summary";import type { FilterType } from "./filters";@@ -207,9 +207,17 @@ export function generateColumns<T>({);}+ if (isMimeValue(value)) {+ return (+ <div className={getCellStyleClass(justify, wrapped)}>+ <MimeCell value={value} />+ </div>+ );+ }+return (<div className={getCellStyleClass(justify, wrapped)}>- <MimeCell value={value} />+ {renderAny(getValue())}</div>);},@@ -301,3 +309,15 @@ function getCellStyleClass(wrapped && "whitespace-pre-wrap min-w-[200px] break-words",);}++function renderAny(value: unknown): React.ReactNode {+ if (value == null) {+ return "";+ }++ try {+ return JSON.stringify(value);+ } catch {+ return String(value);+ }+}diff --git a/frontend/src/components/data-table/mime-cell.tsx b/frontend/src/components/data-table/mime-cell.tsxindex 71e2a4a9c4..f2c4bd35a1 100644--- a/frontend/src/components/data-table/mime-cell.tsx+++ b/frontend/src/components/data-table/mime-cell.tsx@@ -4,18 +4,15 @@ import { OutputRenderer } from "../editor/Output";import type { OutputMessage } from "@/core/kernel/messages";interface MimeCellProps {- value: unknown;+ value: MimeValue;}-export const MimeCell = ({ value }: MimeCellProps) => {- if (typeof value !== "object" || value === null) {- return null;- }-- if (!("mimetype" in value && "data" in value)) {- return null;- }+interface MimeValue {+ mimetype: string;+ data: string;+}+export const MimeCell = ({ value }: MimeCellProps) => {const message = {channel: "output",data: value.data,@@ -29,3 +26,12 @@ export const MimeCell = ({ value }: MimeCellProps) => {</div>);};++export function isMimeValue(value: unknown): value is MimeValue {+ return (+ typeof value === "object" &&+ value !== null &&+ "mimetype" in value &&+ "data" in value+ );+}diff --git a/marimo/_smoke_tests/dataframes/dicts_vs_dfs.py b/marimo/_smoke_tests/dataframes/dicts_vs_dfs.pynew file mode 100644index 0000000000..35bb627007--- /dev/null+++ b/marimo/_smoke_tests/dataframes/dicts_vs_dfs.py@@ -0,0 +1,52 @@+import marimo++__generated_with = "0.11.2"+app = marimo.App(width="medium")+++def _():+ import marimo as mo+ return (mo,)+++def _():+ import polars as pl+ import pandas as pd+ return pd, pl+++def _(pl):+ test_df = pl.DataFrame(+ {+ "str": ["a", "c"],+ "num": [1, 2],+ "list": [["a", "b"], ["c"]],+ "struct": [{"a": 0}, {"a": 1}],+ }+ )+ return (test_df,)+++def _(mo, test_df):+ mo.ui.table(test_df)+ return+++def _(mo, pd, test_df):+ mo.ui.table(pd.DataFrame(test_df.to_dicts()))+ return+++def _(mo, test_df):+ mo.ui.table(test_df.to_dicts())+ return+++if __name__ == "__main__":+ app.run()