Skip to content

Commit 8d61a8e

Browse files
committed
add some tests
1 parent fecaa61 commit 8d61a8e

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

src/danfojs-base/io/node/io.excel.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ const $readExcel = async (filePath: string, options: ExcelInputOptionsNode = {})
7171
const arrBufInt8 = new Uint8Array(arrBuf);
7272
const workbook = read(arrBufInt8, { type: "array", ...parsingOptions });
7373
const worksheet = workbook.Sheets[workbook.SheetNames[sheet]];
74-
const data = utils.sheet_to_json(worksheet,{'defval':null});
74+
const data = utils.sheet_to_json(worksheet, { defval: null });
7575
const df = new DataFrame(data, frameConfig);
7676
resolve(df);
7777
});
@@ -89,7 +89,7 @@ const $readExcel = async (filePath: string, options: ExcelInputOptionsNode = {})
8989

9090
const workbook = readFile(filePath, parsingOptions);
9191
const worksheet = workbook.Sheets[workbook.SheetNames[sheet]];
92-
const data = utils.sheet_to_json(worksheet,{'defval':null});
92+
const data = utils.sheet_to_json(worksheet, { defval: null });
9393
const df = new DataFrame(data, frameConfig);
9494
resolve(df);
9595
})

src/danfojs-node/test/io/excel.reader.test.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,4 +106,23 @@ describe("toExcel", function () {
106106
assert.equal(fs.existsSync(filePath), true)
107107
});
108108

109+
it("handles null values correctly", async function () {
110+
const data = [
111+
{ 'name': 'Alice', 'age': 25 },
112+
{ 'name': null, 'age': 30 },
113+
{ 'name': 'Charlie', 'age': 35 }
114+
];
115+
const df: any = new DataFrame(data);
116+
const filePath = path.join(process.cwd(), "test", "samples", "people.xlsx");
117+
118+
toExcel(df, { filePath, sheetName: 'Sheet1' });
119+
const df2: any = await readExcel(filePath);
120+
121+
assert.deepEqual(df2.values, [
122+
['Alice', 25],
123+
[null, 30],
124+
['Charlie', 35]
125+
]);
126+
assert.deepEqual(df2.columns, ['name', 'age']);
127+
});
109128
})
1.27 KB
Binary file not shown.

0 commit comments

Comments
 (0)