Published
Edited
Jan 8, 2021
1 star
Insert cell
Insert cell
Insert cell
dt = aq.table({
i: [1, 2, 3, undefined, 4, 5],
f: Float32Array.from([1.2, 2.3, 3.0, 3.4, null, 4.5]),
n: [4.5, 4.4, 3.4, 3.0, 2.3, 1.2],
b: [true, true, false, true, null, false],
s: ['foo', null, 'bar', 'baz', 'baz', 'bar'],
d: [date(2000,0,1), date(2000,1,2), null, date(2010,6,9), date(2018,0,1), date(2020,10,3)],
u: [null, null, null, null, null, null],
v: arrow.Int8Vector.from([10, 9, 8, 7, 6, 5]),
a: [[1, null, 3], [4, 5], null, [6, 7], [8, 9], []],
l: [[1], [2], [3], [4], [5], [6]],
o: [1, 2, 3, null, 5].map(v => v ? { key: v } : null)
})
Insert cell
at = toArrowTable(dt)
Insert cell
buffer = at.serialize()
Insert cell
[
compareTables(dt, at),
compareTables(dt, arrow.Table.from(buffer)),
compareTables(aq.fromArrow(arrow.Table.from(buffer)), at)
]
Insert cell
Insert cell
Insert cell
Insert cell
function toArrowTable(table, types = {}) {
const names = table.columnNames();
const vectors = names.map(name => toArrowVector(table, name, types[name]));
return arrow.Table.new(vectors, names);
}
Insert cell
function toArrowVector(table, name, type) {
const column = table.column(name);
const reify = table.isFiltered() || table.isOrdered();
if (!type) {
if (!reify && (column instanceof arrow.Column || column instanceof arrow.Vector)) {
return column;
}
if (isTypedArray(column.data)) {
type = typeMap.get(column.data.constructor.name);
}
}
type = type || inferType(profile(table, name));
const vectorType = getVectorType(type);
// TODO: handle missing type / failed inference
if (!vectorType) return null;
return arrow.Vector.from({ type: vectorType, values: iterator(table, name) });
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more