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 parsing for pandas and ui.table (#1460)

Akshay Agrawal14d74ee7183f
diff --git a/frontend/src/css/admonition.css b/frontend/src/css/admonition.css
index 2ec309e8a8..8777747534 100644
--- a/frontend/src/css/admonition.css
+++ b/frontend/src/css/admonition.css
@@ -25,6 +25,7 @@
.paragraph {
font-weight: initial;
+
@apply text-foreground tracking-normal;
}
}
diff --git a/frontend/src/plugins/impl/vega/loader.ts b/frontend/src/plugins/impl/vega/loader.ts
index 4b43855db2..b2122dd1b1 100644
--- a/frontend/src/plugins/impl/vega/loader.ts
+++ b/frontend/src/plugins/impl/vega/loader.ts
@@ -5,6 +5,7 @@ import { typeParsers, createLoader, read, FieldTypes } from "./vega-loader";
// Augment the typeParsers to support Date
typeParsers.date = (value: string) => new Date(value).toISOString();
+const previousBooleanParser = typeParsers.boolean;
const previousNumberParser = typeParsers.number;
const previousIntegerParser = typeParsers.integer;
@@ -47,6 +48,22 @@ const customNumberParser = (v: string) => {
return previousNumberParser(v);
};
+// Custom boolean parser:
+//
+// Pandas serializes booleans as True/False, but JSON (and vega) requires
+// lowercase
+const customBooleanParser = (v: string) => {
+ if (v === "True") {
+ return true;
+ }
+ if (v === "False") {
+ return false;
+ }
+ return previousBooleanParser(v);
+};
+
+typeParsers.boolean = customBooleanParser;
+
function enableBigInt() {
typeParsers.integer = customIntegerParser;
typeParsers.number = customNumberParser;