Skip to content

Dataframes

The @sluice/nanoarrow-js package implements a high-performance dataframe library for javascript environments.

It includes a set of helper functions to interpret and generate Arrow C Data Interface and Arrow C Stream Interface structures.

It allows fast no-copy memory sharing between the javascript runtime and native (FFI or WASM) bindings.

Whereas the current suite of Arrow implementations provide the basis for a comprehensive data analysis toolkit, this library is intended to support clients that wish to produce or interpret Arrow C Data and/or Arrow C Stream structures where linking to a higher level Arrow binding is not preferred. This library has zero dependencies.

Usage

import {
ArrowArrayJs,
ArrowArrayStruct,
ArrowDictionary,
ArrowNanoType,
ArrowSchemaJs,
ArrowStreamJs,
} from '@sluice/nanoarrow-js';

Constructors

const insertValues = new ArrowArrayStruct(
{ a: ['hello', 'world', null], m: ['sad', 'happy', 'happy'] },
{ a: ArrowNanoType.String, m: mood },
);

Introspect schema and data

Schema Detail

const schema = insertValues.schema.toPortable();

Schema Summary

const schemaStr = insertValues.schema.toPortable();

Data as Rows

const rows = insertValues.rows();

Data as Array of arrays

const arrayofarrays = insertValues.values();

Data as Dataframe

const dataframe = insertValues.dfPlain();

C Interop

C Interface Export

const insertValues = new ArrowArrayStruct(
{ a: ['hello', 'world', null], m: ['sad', 'happy', 'happy'] },
{ a: ArrowNanoType.String, m: mood },
);
expect(insertValues.schema.toString()).toStrictEqual('struct {a:string, m:int8 (dictionary mood string)}');
expect(insertValues.rows()).toStrictEqual([
{
a: 'hello',
m: 'sad',
},
{
a: 'world',
m: 'happy',
},
{
a: null,
m: 'happy',
},
]);
const c = insertValues.toFFI(ffi.memoryInterface);

C Interface import

// const ptrSchema = insertValues.schema.toFFI(ffi.memoryInterface);
// const ptrArray = insertValues.toFFI(ffi.memoryInterface);
const viewSchema = ArrowSchemaJs.fromFFI(ptrSchema, ffi.memoryInterface, insertValues.schema.release);

Arrow Streams

const insertValues = new ArrowArrayStruct(
{ a: ['hello', 'world', null], m: ['sad', 'happy', 'happy'] },
{ a: ArrowNanoType.String, m: mood },
);
const stream = ArrowStreamJs.fromArray(insertValues);
const arrayGenerator = stream.stream();
const arrayFirst = arrayGenerator.next();
const arraySecond = arrayGenerator.next();
// ...