Skip to content

Commit 6af1c6e

Browse files
Copilotmrjf
andauthored
Fix flaky XML round-trip CI failure
Co-authored-by: mrjf <180956+mrjf@users.noreply.github.com>
1 parent f29dbcf commit 6af1c6e

2 files changed

Lines changed: 29 additions & 23 deletions

File tree

src/io/xml.ts

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -417,22 +417,24 @@ export function readXml(text: string, options: ReadXmlOptions = {}): DataFrame {
417417
}
418418

419419
// Build column arrays
420-
const colData: Record<string, Scalar[]> = {};
421-
for (const col of cols) {
422-
colData[col] = rows.map((row) => {
423-
const raw = row[col] ?? null;
424-
if (raw === null || naSet.has(raw)) {
425-
return null;
426-
}
427-
if (converters) {
428-
const n = Number(raw);
429-
if (!Number.isNaN(n) && raw.trim() !== "") {
430-
return n;
420+
const colData = Object.fromEntries(
421+
cols.map((col) => [
422+
col,
423+
rows.map((row) => {
424+
const raw = row[col] ?? null;
425+
if (raw === null || naSet.has(raw)) {
426+
return null;
431427
}
432-
}
433-
return raw;
434-
});
435-
}
428+
if (converters) {
429+
const n = Number(raw);
430+
if (!Number.isNaN(n) && raw.trim() !== "") {
431+
return n;
432+
}
433+
}
434+
return raw;
435+
}),
436+
]),
437+
);
436438

437439
// Determine index
438440
let idxCol: string | null = null;
@@ -445,10 +447,7 @@ export function readXml(text: string, options: ReadXmlOptions = {}): DataFrame {
445447
if (idxCol !== null && cols.includes(idxCol)) {
446448
const idxData = colData[idxCol] ?? [];
447449
const dataColNames = cols.filter((c) => c !== idxCol);
448-
const dataColData: Record<string, Scalar[]> = {};
449-
for (const c of dataColNames) {
450-
dataColData[c] = colData[c] ?? [];
451-
}
450+
const dataColData = Object.fromEntries(dataColNames.map((c) => [c, colData[c] ?? []]));
452451
const idx = new Index(idxData.filter(isLabel));
453452
return DataFrame.fromColumns(dataColData, { index: idx });
454453
}

tests/io/xml.test.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,14 @@ describe("toXml / readXml round-trip", () => {
311311
expect(df2.col("id").toArray()).toEqual([1, 2]);
312312
expect(df2.col("name").toArray()).toEqual(["Alice", "Bob"]);
313313
});
314+
315+
test("round-trips __proto__ column names", () => {
316+
const df = DataFrame.fromColumns(Object.fromEntries([["__proto__", ["Alice", "Bob"]]]));
317+
const xml = toXml(df, { xmlDeclaration: false });
318+
const df2 = readXml(xml, { converters: false });
319+
expect(df2.shape).toEqual(df.shape);
320+
expect(df2.col("__proto__").toArray()).toEqual(["Alice", "Bob"]);
321+
});
314322
});
315323

316324
// ─── property-based tests ─────────────────────────────────────────────────────
@@ -327,10 +335,9 @@ describe("readXml / toXml — property tests", () => {
327335
fc.integer({ min: 1, max: 5 }),
328336
(colNames, nRows) => {
329337
const uniqueCols = [...new Set(colNames)];
330-
const colData: Record<string, string[]> = {};
331-
for (const c of uniqueCols) {
332-
colData[c] = Array.from({ length: nRows }, (_, i) => `v${i}`);
333-
}
338+
const colData = Object.fromEntries(
339+
uniqueCols.map((c) => [c, Array.from({ length: nRows }, (_, i) => `v${i}`)]),
340+
);
334341
const df = DataFrame.fromColumns(colData);
335342
const xml = toXml(df);
336343
const df2 = readXml(xml, { converters: false });

0 commit comments

Comments
 (0)