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: ai prompt context from sql tables with periods (#2663)
Myles Scolnick96645b5176d7
diff --git a/frontend/src/components/editor/ai/__tests__/completion-utils.test.ts b/frontend/src/components/editor/ai/__tests__/completion-utils.test.tsindex 1a43605fa0..7eac839940 100644--- a/frontend/src/components/editor/ai/__tests__/completion-utils.test.ts+++ b/frontend/src/components/editor/ai/__tests__/completion-utils.test.ts@@ -112,4 +112,45 @@ describe("getAICompletionBody", () => {code: "",});});++ it("should handle dataset names with dots", () => {+ // Set up test data in the Jotai store+ const testDatasets = [+ {+ name: "dataset.with.dots",+ columns: [+ { name: "col1", type: "number" },+ { name: "col2", type: "string" },+ ],+ },+ {+ name: "regular_dataset",+ columns: [{ name: "col3", type: "boolean" }],+ },+ ];+ store.set(datasetsAtom, { tables: testDatasets } as DatasetsState);++ const input = "Use @dataset.with.dots and @regular_dataset for analysis";+ const result = getAICompletionBody(input);++ expect(result).toEqual({+ includeOtherCode: "// Some other code",+ context: {+ schema: [+ {+ name: "dataset.with.dots",+ columns: [+ { name: "col1", type: "number" },+ { name: "col2", type: "string" },+ ],+ },+ {+ name: "regular_dataset",+ columns: [{ name: "col3", type: "boolean" }],+ },+ ],+ },+ code: "",+ });+ });});diff --git a/frontend/src/components/editor/ai/completion-utils.ts b/frontend/src/components/editor/ai/completion-utils.tsindex 47630ee696..85ab02602e 100644--- a/frontend/src/components/editor/ai/completion-utils.ts+++ b/frontend/src/components/editor/ai/completion-utils.ts@@ -40,7 +40,7 @@ function extractDatasets(input: string): DataTable[] {const existingDatasets = Maps.keyBy(datasets, (dataset) => dataset.name);// Extract dataset mentions from the input- const mentionedDatasets = input.match(/@(\w+)/g) || [];+ const mentionedDatasets = input.match(/@([\w.]+)/g) || [];// Filter to only include datasets that existreturn mentionedDatasetsdiff --git a/frontend/src/components/editor/chrome/panels/datasources-panel.tsx b/frontend/src/components/editor/chrome/panels/datasources-panel.tsxindex 2a38bf8c5f..7454e81c2a 100644--- a/frontend/src/components/editor/chrome/panels/datasources-panel.tsx+++ b/frontend/src/components/editor/chrome/panels/datasources-panel.tsx@@ -494,7 +494,7 @@ const DatasetColumnPreview: React.FC<{size="icon"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")`;+ const code = `_df = mo.sql(f'SELECT "${column.name}" FROM ${table.name} LIMIT 100')`;onAddColumnChart(code);})}>diff --git a/frontend/src/core/edit-app.tsx b/frontend/src/core/edit-app.tsxindex 42e650ae04..547eecd6d6 100644--- a/frontend/src/core/edit-app.tsx+++ b/frontend/src/core/edit-app.tsx@@ -308,7 +308,7 @@ export const EditApp: React.FC<AppProps> = ({ userConfig, appConfig }) => {<AppHeaderconnection={connection}className={cn(- "pt-4 sm:pt-12 pb-2 mb-4 print:hidden",+ "pt-4 sm:pt-12 pb-2 mb-4 print:hidden z-50",// Keep the header sticky when scrolling horizontally, for column mode"sticky left-0",)}diff --git a/marimo/_data/preview_column.py b/marimo/_data/preview_column.pyindex 735b008184..1f855cf6cb 100644--- a/marimo/_data/preview_column.py+++ b/marimo/_data/preview_column.py@@ -45,7 +45,9 @@ def get_column_preview_dataframe(# Get the summary of the columntry:summary = table.get_summary(column_name)- except Exception as e:+ except BaseException as e:+ # Catch-all: some libraries like Polars have bugs and raise+ # BaseExceptions, which shouldn't crash the kernelLOGGER.warning("Failed to get summary for column %s in table %s",column_name,diff --git a/marimo/_plugins/ui/_impl/table.py b/marimo/_plugins/ui/_impl/table.pyindex cb17368a5c..bddba7be27 100644--- a/marimo/_plugins/ui/_impl/table.py+++ b/marimo/_plugins/ui/_impl/table.py@@ -430,18 +430,23 @@ class table(UIElement[List[str], Union[List[JSONType], IntoDataFrame]]):# Get column summariessummaries: List[ColumnSummary] = []for column in self._manager.get_column_names():- summary = self._searched_manager.get_summary(column)- summaries.append(- ColumnSummary(- column=column,- nulls=summary.nulls,- min=summary.min,- max=summary.max,- unique=summary.unique,- true=summary.true,- false=summary.false,+ try:+ summary = self._searched_manager.get_summary(column)+ summaries.append(+ ColumnSummary(+ column=column,+ nulls=summary.nulls,+ min=summary.min,+ max=summary.max,+ unique=summary.unique,+ true=summary.true,+ false=summary.false,+ ))- )+ except BaseException:+ # Catch-all: some libraries like Polars have bugs and raise+ # BaseExceptions, which shouldn't crash the kernel+ LOGGER.warning("Failed to get summary for column %s", column)# If we are above the limit to show charts,# we don't return the chart data