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: boolean charts in table headers for pandas (#2291)

Myles Scolnick1c760e361876
diff --git a/frontend/src/components/data-table/chart-spec-model.tsx b/frontend/src/components/data-table/chart-spec-model.tsx
index 4e0e6edbda..eccea16c8b 100644
--- a/frontend/src/components/data-table/chart-spec-model.tsx
+++ b/frontend/src/components/data-table/chart-spec-model.tsx
@@ -4,6 +4,8 @@ import { mint, orange, slate } from "@radix-ui/colors";
import type { ColumnHeaderSummary, FieldTypes } from "./types";
import { asURL } from "@/utils/url";
+const MAX_BAR_HEIGHT = 24; // px
+
export class ColumnChartSpecModel<T> {
private columnSummaries = new Map<string | number, ColumnHeaderSummary>();
@@ -137,7 +139,8 @@ export class ColumnChartSpecModel<T> {
field: column,
type: "nominal",
axis: {
- labelExpr: "datum.label === 'true' ? 'True' : 'False'",
+ labelExpr:
+ "datum.label === 'true' || datum.label === 'True' ? 'True' : 'False'",
tickWidth: 0,
title: null,
labelColor: slate.slate9,
@@ -150,7 +153,7 @@ export class ColumnChartSpecModel<T> {
scale: { type: "linear" },
},
tooltip: [
- { field: column, type: "nominal", format: ",d", title: "Value" },
+ { field: column, type: "nominal", title: "Value" },
{
aggregate: "count",
type: "quantitative",
@@ -161,7 +164,11 @@ export class ColumnChartSpecModel<T> {
},
layer: [
{
- mark: { type: "bar", color: mint.mint11 },
+ mark: {
+ type: "bar",
+ color: mint.mint11,
+ height: MAX_BAR_HEIGHT,
+ },
},
{
mark: {
diff --git a/marimo/_smoke_tests/tables/booleans.py b/marimo/_smoke_tests/tables/booleans.py
new file mode 100644
index 0000000000..6c7ff87fbd
--- /dev/null
+++ b/marimo/_smoke_tests/tables/booleans.py
@@ -0,0 +1,48 @@
+# /// script
+# requires-python = ">=3.11"
+# dependencies = [
+# "marimo",
+# "pandas",
+# ]
+# ///
+
+import marimo
+
+__generated_with = "0.8.14"
+app = marimo.App(width="medium")
+
+
+def __():
+ import marimo as mo
+ import pandas as pd
+ import polars as pl
+ return mo, pd, pl
+
+
+def __(pd):
+ data = {
+ "A": [True, True, True],
+ "B": [False, False, False],
+ "C": [True, True, False],
+ }
+
+ pd.DataFrame(data)
+ return data,
+
+
+def __(data, pl):
+ pl.DataFrame(data)
+ return
+
+
+def __(data, mo):
+ mo.ui.table(data)
+ return
+
+
+if __name__ == "__main__":
+ app.run()