DataFrame processing: Require table rows to be array (#20357)

This commit is contained in:
Šimon Podlipský 2019-11-13 14:30:08 +01:00 committed by Dominik Prokop
parent 17fe704ae8
commit 4260cd548f
2 changed files with 14 additions and 3 deletions

View File

@ -59,6 +59,15 @@ describe('toDataFrame', () => {
expect(again).toBe(input);
});
it('throws when table rows is not array', () => {
expect(() =>
toDataFrame({
columns: [],
rows: {},
})
).toThrowError('Expected table rows to be array, got object.');
});
it('migrate from 6.3 style rows', () => {
const oldDataFrame = {
fields: [{ name: 'A' }, { name: 'B' }, { name: 'C' }],

View File

@ -1,7 +1,5 @@
// Libraries
import isNumber from 'lodash/isNumber';
import isString from 'lodash/isString';
import isBoolean from 'lodash/isBoolean';
import { isArray, isBoolean, isNumber, isString } from 'lodash';
// Types
import {
@ -34,6 +32,10 @@ function convertTableToDataFrame(table: TableData): DataFrame {
};
});
if (!isArray(table.rows)) {
throw new Error(`Expected table rows to be array, got ${typeof table.rows}.`);
}
for (const row of table.rows) {
for (let i = 0; i < fields.length; i++) {
fields[i].values.buffer.push(row[i]);