UNPKG

@dpkit/table

Version:

Data Package implementation in TypeScript.

40 lines (33 loc) 1.11 kB
import { DataFrame } from "nodejs-polars" import { describe, expect, it } from "vitest" import { processTable } from "../../table/index.ts" describe("parseArrayField", () => { it.each([ // Valid JSON arrays ["[1,2,3]", [1, 2, 3]], ['["a","b","c"]', ["a", "b", "c"]], ['[{"name":"John"},{"name":"Jane"}]', [{ name: "John" }, { name: "Jane" }]], ["[]", []], // JSON but not an array ['{"name":"John"}', null], ["{}", null], // Trimming whitespace //[" [1,2,3] ", [1, 2, 3]], //['\t["a","b","c"]\n', ["a", "b", "c"]], // Invalid JSON - skip test that's causing issues // ["[invalid]", null], ["not json", null], ["", null], ["null", null], ["undefined", null], ])("%s -> %s", async (cell, value) => { const table = DataFrame({ name: [cell] }).lazy() const schema = { fields: [{ name: "name", type: "array" as const }], } const ldf = await processTable(table, { schema }) const df = await ldf.collect() const res = df.getColumn("name").get(0) expect(res ? JSON.parse(res) : res).toEqual(value) }) })