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.

improvement: refetch stale dataset column previews, fix: dataset column summary for non-hashable columns (#1526)

Myles Scolnickc7c98848a941
diff --git a/frontend/src/core/datasets/state.ts b/frontend/src/core/datasets/state.ts
index 51e6cd9b72..9ed984eb93 100644
--- a/frontend/src/core/datasets/state.ts
+++ b/frontend/src/core/datasets/state.ts
@@ -5,6 +5,7 @@ import type { DatasetsState } from "./types";
import { useAtomValue } from "jotai";
import { VariableName } from "../variables/types";
import { DataColumnPreview } from "../kernel/messages";
+import { previewDatasetColumn } from "../network/requests";
function initialState(): DatasetsState {
return {
@@ -22,8 +23,25 @@ const {
useActions,
} = createReducerAndAtoms(initialState, {
addDatasets: (state, datasets: Pick<DatasetsState, "tables">) => {
+ // Quietly in the background make requests to get the previews for
+ // opened columns, in the new tables
+ for (const table of datasets.tables) {
+ for (const column of table.columns) {
+ const tableColumn = `${table.name}:${column.name}` as const;
+ if (state.expandedColumns.has(tableColumn)) {
+ // Fire and forget
+ void previewDatasetColumn({
+ tableName: table.name,
+ columnName: column.name,
+ source: table.source,
+ });
+ }
+ }
+ }
+
// Put new tables at the top
const newTables = [...datasets.tables, ...state.tables];
+
// Dedupe by name and source
const seen = new Set();
const dedupedTables = newTables.filter((table) => {
diff --git a/marimo/_plugins/ui/_impl/tables/pandas_table.py b/marimo/_plugins/ui/_impl/tables/pandas_table.py
index 74c9673075..4ad4a0882b 100644
--- a/marimo/_plugins/ui/_impl/tables/pandas_table.py
+++ b/marimo/_plugins/ui/_impl/tables/pandas_table.py
@@ -160,11 +160,19 @@ class PandasTableManagerFactory(TableManagerFactory):
col = self.data[column]
if col.dtype == "object":
- return ColumnSummary(
- total=col.count(),
- nulls=col.isnull().sum(),
- unique=col.nunique(),
- )
+ try:
+ return ColumnSummary(
+ total=col.count(),
+ nulls=col.isnull().sum(),
+ unique=col.nunique(),
+ )
+ except TypeError:
+ # If the column is not hashable,
+ # we can't get the unique values
+ return ColumnSummary(
+ total=col.count(),
+ nulls=col.isnull().sum(),
+ )
if col.dtype == "bool":
return ColumnSummary(
diff --git a/marimo/_smoke_tests/datasources.py b/marimo/_smoke_tests/datasources.py
index 0151d647b1..8af1d3663a 100644
--- a/marimo/_smoke_tests/datasources.py
+++ b/marimo/_smoke_tests/datasources.py
@@ -2,7 +2,7 @@
import marimo
-__generated_with = "0.6.11"
+__generated_with = "0.6.13"
app = marimo.App(width="full")
@@ -10,7 +10,20 @@ app = marimo.App(width="full")
def __():
import marimo as mo
from vega_datasets import data
- return data, mo
+ import pandas as pd
+ return data, mo, pd
+
+
+def __(pd):
+ editable_table = pd.DataFrame({"a": [2, 2, 12], "b": [2, 5, 6]})
+ return editable_table,
+
+
+def __(pd):
+ df_with_list = pd.DataFrame([{"a": [1, 2, 3]}])
+ return df_with_list,
@app.cell
@@ -31,6 +44,7 @@ def __(data, dropdown, mo):
@app.cell
def __(df):
import polars as pl
+
polars_df = pl.DataFrame(df)
return pl, polars_df
@@ -38,6 +52,7 @@ def __(df):
@app.cell
def __(df):
import pyarrow as pa
+
pyarrow_df = pa.Table.from_pandas(df)
return pa, pyarrow_df
diff --git a/tests/_plugins/ui/_impl/tables/test_pandas_table.py b/tests/_plugins/ui/_impl/tables/test_pandas_table.py
index 3dc301e9d8..2d2b742c91 100644
--- a/tests/_plugins/ui/_impl/tables/test_pandas_table.py
+++ b/tests/_plugins/ui/_impl/tables/test_pandas_table.py
@@ -36,6 +36,8 @@ class TestPandasTableManager(unittest.TestCase):
datetime.datetime(2021, 1, 2),
datetime.datetime(2021, 1, 3),
],
+ # List
+ "F": [[1, 2, 3], [4, 5, 6], [7, 8, 9]],
}
)
self.manager = self.factory.create()(self.data)
@@ -61,7 +63,7 @@ class TestPandasTableManager(unittest.TestCase):
def test_select_rows_empty(self) -> None:
selected_manager = self.manager.select_rows([])
- assert selected_manager.data.shape == (0, 5)
+ assert selected_manager.data.shape == (0, 6)
def test_get_row_headers(self) -> None:
expected_headers = []
@@ -134,6 +136,7 @@ class TestPandasTableManager(unittest.TestCase):
"C": "number",
"D": "boolean",
"E": "date",
+ "F": "string",
}
assert self.manager.get_field_types() == expected_field_types
@@ -314,3 +317,11 @@ class TestPandasTableManager(unittest.TestCase):
p75=pd.Timestamp("2021-01-02 12:00:00"),
p95=pd.Timestamp("2021-01-02 21:36:00"),
)
+
+ def test_summary_list(self) -> None:
+ column = "F"
+ summary = self.manager.get_summary(column)
+ assert summary == ColumnSummary(
+ total=3,
+ nulls=0,
+ )