Skip to content

Commit

Permalink
Moved DataFrame ops to Table. DataFrame is now an interface
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian Hulette committed Jan 12, 2018
1 parent e8979ba commit 1d60aa1
Show file tree
Hide file tree
Showing 7 changed files with 158 additions and 226 deletions.
19 changes: 9 additions & 10 deletions js/perf/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,17 +124,16 @@ function createGetByIndexTest(vector) {
}

function createDataFrameDirectCountTest(table, column, test, value) {
let df = DataFrame.from(table);
let colidx = table.columns.findIndex((c)=>c.name === column);

if (test == 'gteq') {
op = function () {
sum = 0;
for (let batch = -1; ++batch < df.lengths.length;) {
const length = df.lengths[batch];
for (let batch = -1; ++batch < table.lengths.length;) {
const length = table.lengths[batch];

// load batches
const columns = df.batches[batch];
const columns = table.batches[batch];

// yield all indices
for (let idx = -1; ++idx < length;) {
Expand All @@ -145,11 +144,11 @@ function createDataFrameDirectCountTest(table, column, test, value) {
} else if (test == 'eq') {
op = function() {
sum = 0;
for (let batch = -1; ++batch < df.lengths.length;) {
const length = df.lengths[batch];
for (let batch = -1; ++batch < table.lengths.length;) {
const length = table.lengths[batch];

// load batches
const columns = df.batches[batch]
const columns = table.batches[batch]

// yield all indices
for (let idx = -1; ++idx < length;) {
Expand All @@ -169,13 +168,13 @@ function createDataFrameDirectCountTest(table, column, test, value) {
}

function createDataFrameFilterCountTest(table, column, test, value) {
let df = DataFrame.from(table);
let colidx = table.columns.findIndex((c)=>c.name === column);
let df;

if (test == 'gteq') {
df = df.filter(col(column).gteq(value));
df = table.filter(col(column).gteq(value));
} else if (test == 'eq') {
df = df.filter(col(column).eq(value));
df = table.filter(col(column).eq(value));
} else {
throw new Error(`Unrecognized test "${test}"`);
}
Expand Down
12 changes: 4 additions & 8 deletions js/src/Arrow.externs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ Table.prototype.key;
Table.prototype.select;
/** @type {?} */
Table.prototype.toString;
/** @type {?} */
Table.prototype.lengths;
/** @type {?} */
Table.prototype.batches;

let Vector = function() {};
/** @type {?} */
Expand Down Expand Up @@ -83,14 +87,6 @@ DictionaryVector.prototype.getKey;
/** @type {?} */
DictionaryVector.prototype.getValue;

let DataFrame = function () {};
/** @type {?} */
DataFrame.prototype.lengths;
/** @type {?} */
DataFrame.prototype.columns;
/** @type {?} */
DataFrame.prototype.batches;

let Col = function() {};
/** @type {?} */
Col.prototype.gteq;
Expand Down
8 changes: 2 additions & 6 deletions js/src/Arrow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,14 @@ import {
TimestampVector,
} from './vector/numeric';

import { DataFrame } from './dataframe/dataframe';
import { lit, col } from './dataframe/predicate';
import { lit, col } from './vector/predicate';

// closure compiler always erases static method names:
// https://github.com/google/closure-compiler/issues/1776
// set them via string indexers to save them from the mangler
Table['from'] = Table.from;
Table['fromAsync'] = Table.fromAsync;
BoolVector['pack'] = BoolVector.pack;
DataFrame['from'] = DataFrame.from;

export { read, readAsync };
export { Table, Vector, StructRow };
Expand Down Expand Up @@ -88,8 +86,7 @@ export {
FixedSizeListVector,
};

export { DataFrame } from './dataframe/dataframe';
export { lit, col } from './dataframe/predicate';
export { lit, col } from './vector/predicate';


/* These exports are needed for the closure umd targets */
Expand All @@ -103,7 +100,6 @@ try {
Arrow['readAsync'] = readAsync;
Arrow['Table'] = Table;
Arrow['Vector'] = Vector;
Arrow['DataFrame'] = DataFrame;
Arrow['StructRow'] = StructRow;
Arrow['BoolVector'] = BoolVector;
Arrow['ListVector'] = ListVector;
Expand Down
2 changes: 1 addition & 1 deletion js/src/bin/arrow2csv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ files.forEach((source) => {
printTable(table);
});

function printTable(table: Arrow.Table<any>) {
function printTable(table: Arrow.Table) {
let header = [...table.columns.map((_, i) => table.key(i))].map(stringify);
let maxColumnWidths = header.map(x => x.length);
// Pass one to convert to strings and count max column widths
Expand Down
179 changes: 0 additions & 179 deletions js/src/dataframe/dataframe.ts

This file was deleted.

File renamed without changes.
Loading

0 comments on commit 1d60aa1

Please sign in to comment.