Skip to content

Commit 7bc7363

Browse files
author
Brian Hulette
committed
Fix exception for empty Table
1 parent 8ddce0a commit 7bc7363

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

js/src/table.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,9 @@ export class Table implements DataFrame {
101101
}
102102
this.schema = schema;
103103
this.batches = batches;
104-
this.batchesUnion = batches.reduce((union, batch) => union.concat(batch));
104+
this.batchesUnion = batches.length == 0 ?
105+
new RecordBatch(schema, 0, []) :
106+
batches.reduce((union, batch) => union.concat(batch));
105107
this.length = this.batchesUnion.length;
106108
this.numCols = this.batchesUnion.numCols;
107109
}

js/test/unit/table-tests.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ const {
2424
} = Arrow;
2525

2626
describe(`Table`, () => {
27+
test(`can create an empty table`, () => {
28+
expect(Table.empty().length).toEqual(0)
29+
});
30+
2731
describe(`single record batch`, () => {
2832
const table = Table.from({
2933
'schema': {

0 commit comments

Comments
 (0)