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): skip chart for nested/unknown column types (#9876)

Kiran Gadhave88be96007d9b
diff --git a/marimo/_data/preview_column.py b/marimo/_data/preview_column.py
index f677ca540f..26f28bb523 100644
--- a/marimo/_data/preview_column.py
+++ b/marimo/_data/preview_column.py
@@ -235,6 +235,11 @@ def _get_altair_chart(
(column_type, _external_type) = table.get_field_type(column_name)
+ # Nested/unknown dtypes (e.g. Polars Struct/List) can't be serialized
+ # through the dataframe interchange path, so skip charting silently
+ if column_type == "unknown":
+ return None, None, None, None
+
if stats.total == 0:
return None, None, "Table is empty", None
diff --git a/tests/_data/test_preview_column.py b/tests/_data/test_preview_column.py
index 8d73c5c765..16b322dd32 100644
--- a/tests/_data/test_preview_column.py
+++ b/tests/_data/test_preview_column.py
@@ -574,6 +574,32 @@ def test_sanitize_dtypes_enum() -> None:
assert result.collect_schema()["enum_col"] == nw.String
+ not DependencyManager.narwhals.has()
+ or not DependencyManager.polars.has()
+ or not DependencyManager.altair.has(),
+ reason="narwhals, polars and altair not installed",
+)
+def test_preview_column_struct_skips_chart() -> None:
+ import polars as pl
+
+ df = pl.DataFrame({"struct_col": [{"a": 1, "b": "x"}, {"a": 2, "b": "y"}]})
+
+ with patch("marimo._data.preview_column.LOGGER") as mock_logger:
+ result = get_column_preview_dataset(
+ table=get_table_manager(df),
+ table_name="table",
+ column_name="struct_col",
+ )
+
+ assert result is not None
+ assert result.error is None
+ assert result.chart_spec is None
+ assert result.chart_code is None
+ assert result.stats is not None
+ mock_logger.warning.assert_not_called()
+
+
@pytest.mark.parametrize(
"df",
create_dataframes(