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
improvement: enable column previews for only in-memory (#2573)
Myles Scolnickee4a5f2a8792
diff --git a/frontend/src/components/editor/chrome/panels/datasources-panel.tsx b/frontend/src/components/editor/chrome/panels/datasources-panel.tsxindex f75228c249..2a38bf8c5f 100644--- a/frontend/src/components/editor/chrome/panels/datasources-panel.tsx+++ b/frontend/src/components/editor/chrome/panels/datasources-panel.tsx@@ -477,7 +477,7 @@ const DatasetColumnPreview: React.FC<{<Buttonvariant="outline"size="icon"- className="z-10 bg-background absolute right-1 top-0"+ className="z-10 bg-background absolute right-1 -top-1"onClick={Events.stopPropagation(() =>onAddColumnChart(preview.chart_code || ""),)}@@ -492,7 +492,7 @@ const DatasetColumnPreview: React.FC<{<Buttonvariant="outline"size="icon"- className="z-10 bg-background absolute right-1 top-0"+ className="z-10 bg-background absolute right-1 -top-1"onClick={Events.stopPropagation(() => {const code = `_df = mo.sql(f"SELECT '${column.name}' FROM ${table.name} LIMIT 100")`;onAddColumnChart(code);diff --git a/marimo/_data/preview_column.py b/marimo/_data/preview_column.pyindex 918b9b4b48..e12edad891 100644--- a/marimo/_data/preview_column.py+++ b/marimo/_data/preview_column.py@@ -118,11 +118,16 @@ def get_column_preview_for_sql(table_name: str,column_name: str,) -> Optional[DataColumnPreview]:- # Drop memory.main- if table_name.startswith("memory.main."):- query_table_name = table_name.replace("memory.main.", "")- else:- query_table_name = table_name+ # Only show column previews for in-memory tables+ # otherwise we could be making requests to postgres/mysql/etc+ # that the user may not intend to do so.+ if not table_name.startswith("memory.main."):+ return DataColumnPreview(+ table_name=table_name,+ column_name=column_name,+ error="Previews only supported for in-memory tables",+ )+ query_table_name = table_name.replace("memory.main.", "")column_type = get_column_type(query_table_name, column_name)summary = get_sql_summary(query_table_name, column_name, column_type)@@ -137,7 +142,6 @@ def get_column_preview_for_sql(chart_builder = get_chart_builder(column_type, False)try:chart_spec = chart_builder.altair_json(histogram_data, column_name)- chart_code = chart_builder.altair_code(table_name, column_name)except Exception as e:LOGGER.warning(f"Failed to generate Altair chart: {str(e)}")diff --git a/tests/_data/test_preview_column.py b/tests/_data/test_preview_column.pyindex d65f9e0677..ae45c25762 100644--- a/tests/_data/test_preview_column.py+++ b/tests/_data/test_preview_column.py@@ -104,7 +104,7 @@ def test_get_column_preview_for_duckdb() -> None:# Test preview for the 'outcome' column (alternating 0 and 1)result = get_column_preview_for_sql(- table_name="tbl",+ table_name="memory.main.tbl",column_name="outcome",)assert result is not None@@ -118,7 +118,7 @@ def test_get_column_preview_for_duckdb() -> None:# Test preview for the 'id' column (for comparison)result_id = get_column_preview_for_sql(- table_name="tbl",+ table_name="memory.main.tbl",column_name="id",)assert result_id is not None@@ -154,7 +154,7 @@ def test_get_column_preview_for_duckdb_categorical() -> None:""")result_categorical = get_column_preview_for_sql(- table_name="tbl",+ table_name="memory.main.tbl",column_name="category",)assert result_categorical is not None@@ -191,7 +191,7 @@ def test_get_column_preview_for_duckdb_date() -> None:""")result_date = get_column_preview_for_sql(- table_name="date_tbl",+ table_name="memory.main.date_tbl",column_name="date_col",)assert result_date is not None@@ -228,7 +228,7 @@ def test_get_column_preview_for_duckdb_bool() -> None:""")result_bool = get_column_preview_for_sql(- table_name="bool_tbl",+ table_name="memory.main.bool_tbl",column_name="bool_col",)assert result_bool is not None