From 6ce4f842718a1e1e127fd1607b212501a1bb650d Mon Sep 17 00:00:00 2001 From: Gatefixer <313497061+lancedb-gatefixer[bot]@users.noreply.github.com> Date: Wed, 5 Aug 2026 17:56:39 +0000 Subject: [PATCH] fix(node): validate inferred types across records --- nodejs/__test__/arrow.test.ts | 12 ++++++++++++ nodejs/lancedb/arrow.ts | 9 +++++---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/nodejs/__test__/arrow.test.ts b/nodejs/__test__/arrow.test.ts index 9e20e3c04..55aae754e 100644 --- a/nodejs/__test__/arrow.test.ts +++ b/nodejs/__test__/arrow.test.ts @@ -449,6 +449,18 @@ describe.each([arrow15, arrow16, arrow17, arrow18])( ); }); + it("will allow matching inferred types across records", function () { + expect(() => + makeArrowTable([{ value: 1 }, { value: 2 }]), + ).not.toThrow(); + }); + + it("will reject mismatched inferred types across records", function () { + expect(() => makeArrowTable([{ value: 1 }, { value: "two" }])).toThrow( + "Failed to infer schema for data. Previously inferred type Float64 but found Utf8 at row 1. Consider providing an explicit schema.", + ); + }); + it("will allow a schema to be provided", async function () { await checkTableCreation( async (records, _, schema) => diff --git a/nodejs/lancedb/arrow.ts b/nodejs/lancedb/arrow.ts index 587d30b19..b0decd481 100644 --- a/nodejs/lancedb/arrow.ts +++ b/nodejs/lancedb/arrow.ts @@ -489,10 +489,11 @@ function inferSchema( } else if (schema === undefined) { const currentType = pathTree.get(path); const newType = inferType(value, path, opts); - if (currentType !== newType) { - new Error(`Failed to infer schema for data. Previously inferred type \ - ${currentType} but found ${newType} at row ${rowI}. Consider \ - providing an explicit schema.`); + if (currentType?.toString() !== newType?.toString()) { + throw new Error( + `Failed to infer schema for data. Previously inferred type ${currentType} ` + + `but found ${newType} at row ${rowI}. Consider providing an explicit schema.`, + ); } } }