Commit 4260cd54 by Šimon Podlipský Committed by Dominik Prokop

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

parent 17fe704a
......@@ -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' }],
......
// 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]);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment