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: add string conversion in DataTableColumn post-init (#6383)

Myles Scolnickd0b0a504703e
diff --git a/marimo/_data/models.py b/marimo/_data/models.py
index 535a39c289..c25575fe72 100644
--- a/marimo/_data/models.py
+++ b/marimo/_data/models.py
@@ -39,6 +39,12 @@ class DataTableColumn(msgspec.Struct):
external_type: ExternalDataType
sample_values: list[Any]
+ def __post_init__(self) -> None:
+ # Sometimes like pandas, sqlalchemy or ibis may return column names as objects
+ # instead of strings, although their type hints are str
+ # Instead of trying to track this down each time, just convert to string
+ self.name = str(self.name)
+
# Local -> Python dataframes
# DuckDB -> DuckDB tables using the global in-memory DuckDB instance
diff --git a/tests/_data/test_models.py b/tests/_data/test_models.py
new file mode 100644
index 0000000000..427a7c13ba
--- /dev/null
+++ b/tests/_data/test_models.py
@@ -0,0 +1,11 @@
+from marimo._data.models import DataTableColumn
+
+
+def test_data_table_column_post_init() -> None:
+ column = DataTableColumn(
+ name=123,
+ type="string",
+ external_type="string",
+ sample_values=[],
+ )
+ assert column.name == "123"