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: float parsing altair (#739)

Myles Scolnick5e02f89f58bc
diff --git a/frontend/src/plugins/impl/vega/__tests__/vega.test.ts b/frontend/src/plugins/impl/vega/__tests__/vega.test.ts
index ad5f727a0c..35ace8eec3 100644
--- a/frontend/src/plugins/impl/vega/__tests__/vega.test.ts
+++ b/frontend/src/plugins/impl/vega/__tests__/vega.test.ts
@@ -8,7 +8,7 @@ import {
} from "../loader";
describe("vega loader", () => {
- it("should parse csv data", async () => {
+ it("should parse csv data with dates", async () => {
const csvData = `
active,username,id
2023-08-14T19:28:47Z,akshayka,1994308
@@ -34,6 +34,44 @@ active,username,id
]
`);
});
+
+ it("should parse csv data with floats", async () => {
+ const csvData = `
+yield_error,yield_center
+7.5522,32.4
+6.9775,30.96667
+3.9167,33.966665
+11.9732,30.45
+`.trim();
+
+ vi.spyOn(vegaLoader, "load").mockReturnValue(Promise.resolve(csvData));
+
+ const data = await vegaLoadData(csvData, { type: "csv", parse: "auto" });
+ const dataWithoutParseAuto = await vegaLoadData(csvData, { type: "csv" });
+
+ expect(data).toEqual(dataWithoutParseAuto);
+
+ expect(data).toMatchInlineSnapshot(`
+ [
+ {
+ "yield_center": 32.4,
+ "yield_error": 7.5522,
+ },
+ {
+ "yield_center": 30.96667,
+ "yield_error": 6.9775,
+ },
+ {
+ "yield_center": 33.966665,
+ "yield_error": 3.9167,
+ },
+ {
+ "yield_center": 30.45,
+ "yield_error": 11.9732,
+ },
+ ]
+ `);
+ });
});
describe("uniquifyColumnNames", () => {
diff --git a/frontend/src/plugins/impl/vega/loader.ts b/frontend/src/plugins/impl/vega/loader.ts
index b2477a8603..53ebdfa114 100644
--- a/frontend/src/plugins/impl/vega/loader.ts
+++ b/frontend/src/plugins/impl/vega/loader.ts
@@ -27,7 +27,11 @@ export function vegaLoadData(
// we would need to store the data in columnar format.
csvData = uniquifyColumnNames(csvData);
- // csv -> json
+ // Always set parse to auto for csv data, to be able to parse dates and floats
+ if (format && format.type === "csv") {
+ // csv -> json
+ return read(csvData, { ...format, parse: "auto" });
+ }
return read(csvData, format);
});
}