Skip to content

Commit

Permalink
Merge branch 'table-scan-perf' of github.com:ccri/arrow into js-cpp-r…
Browse files Browse the repository at this point in the history
…efactor
  • Loading branch information
trxcllnt committed Jan 22, 2018
2 parents b7f5bfb + 0620cfd commit 87334a5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 24 deletions.
4 changes: 2 additions & 2 deletions js/src/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ export class Table implements DataFrame {
}
}
}
public count(): number { return this.batchesUnion.length; }
public count(): number { return this.length; }
public countBy(name: Col | string): CountByResult {
const batches = this.batches, numBatches = batches.length;
const count_by = typeof name === 'string' ? new Col(name) : name;
Expand Down Expand Up @@ -264,7 +264,7 @@ export class CountByResult extends Table implements DataFrame {
counts.length, [values, counts]
));
}
public asJSON(): Object {
public toJSON(): Object {
const [values, counts] = this.columns;
const result = {} as { [k: string]: number | null };
for (let i = -1; ++i < this.length;) {
Expand Down
44 changes: 22 additions & 22 deletions js/test/unit/table-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,13 @@ describe(`Table`, () => {
// Wrap floating point values in a Float32Array and take them back out to
// make sure that equality checks will pass
const values = [
[new Float32Array([-0.3])[0], -1, 'a'],
[new Float32Array([-0.2])[0], 1, 'b'],
[new Float32Array([-0.1])[0], -1, 'c'],
[new Float32Array([ 0 ])[0], 1, 'a'],
[new Float32Array([ 0.1])[0], -1, 'b'],
[new Float32Array([ 0.2])[0], 1, 'c'],
[new Float32Array([ 0.3])[0], -1, 'a']
[Math.fround(-0.3), -1, 'a'],
[Math.fround(-0.2), 1, 'b'],
[Math.fround(-0.1), -1, 'c'],
[Math.fround( 0 ), 1, 'a'],
[Math.fround( 0.1), -1, 'b'],
[Math.fround( 0.2), 1, 'c'],
[Math.fround( 0.3), -1, 'a']
];
test(`has the correct length`, () => {
expect(table.length).toEqual(values.length);
Expand Down Expand Up @@ -161,19 +161,19 @@ describe(`Table`, () => {
test(`countBy on dictionary returns the correct counts`, () => {
// Make sure countBy works both with and without the Col wrapper
// class
expect(table.countBy(col('dictionary')).asJSON()).toEqual({
expect(table.countBy(col('dictionary')).toJSON()).toEqual({
'a': 3,
'b': 2,
'c': 2,
});
expect(table.countBy('dictionary').asJSON()).toEqual({
expect(table.countBy('dictionary').toJSON()).toEqual({
'a': 3,
'b': 2,
'c': 2,
});
});
test(`countBy on dictionary with filter returns the correct counts`, () => {
expect(table.filter(col('i32').eq(1)).countBy('dictionary').asJSON()).toEqual({
expect(table.filter(col('i32').eq(1)).countBy('dictionary').toJSON()).toEqual({
'a': 1,
'b': 1,
'c': 1,
Expand Down Expand Up @@ -321,15 +321,15 @@ describe(`Table`, () => {
// Wrap floating point values in a Float32Array and take them back out to
// make sure that equality checks will pass
const values = [
[new Float32Array([-0.3])[0], -1, 'a'],
[new Float32Array([-0.2])[0], 1, 'b'],
[new Float32Array([-0.1])[0], -1, 'c'],
[new Float32Array([ 0 ])[0], 1, 'a'],
[new Float32Array([ 0.1])[0], -1, 'b'],
[new Float32Array([ 0.2])[0], 1, 'c'],
[new Float32Array([ 0.3])[0], -1, 'a'],
[new Float32Array([ 0.2])[0], 1, 'b'],
[new Float32Array([ 0.1])[0], -1, 'c'],
[Math.fround(-0.3), -1, 'a'],
[Math.fround(-0.2), 1, 'b'],
[Math.fround(-0.1), -1, 'c'],
[Math.fround( 0 ), 1, 'a'],
[Math.fround( 0.1), -1, 'b'],
[Math.fround( 0.2), 1, 'c'],
[Math.fround( 0.3), -1, 'a'],
[Math.fround( 0.2), 1, 'b'],
[Math.fround( 0.1), -1, 'c'],
];
test(`has the correct length`, () => {
expect(table.length).toEqual(values.length);
Expand Down Expand Up @@ -366,19 +366,19 @@ describe(`Table`, () => {
test(`countBy on dictionary returns the correct counts`, () => {
// Make sure countBy works both with and without the Col wrapper
// class
expect(table.countBy(col('dictionary')).asJSON()).toEqual({
expect(table.countBy(col('dictionary')).toJSON()).toEqual({
'a': 3,
'b': 3,
'c': 3,
});
expect(table.countBy('dictionary').asJSON()).toEqual({
expect(table.countBy('dictionary').toJSON()).toEqual({
'a': 3,
'b': 3,
'c': 3,
});
});
test(`countBy on dictionary with filter returns the correct counts`, () => {
expect(table.filter(col('i32').eq(1)).countBy(col('dictionary')).asJSON()).toEqual({
expect(table.filter(col('i32').eq(1)).countBy(col('dictionary')).toJSON()).toEqual({
'a': 1,
'b': 2,
'c': 1,
Expand Down

0 comments on commit 87334a5

Please sign in to comment.