From e761eeeb542f030a209c40861a4ade3d9997dc7b Mon Sep 17 00:00:00 2001 From: Brian Hulette Date: Tue, 16 Jan 2018 15:53:31 -0500 Subject: [PATCH 1/3] Rename asJSON to toJSON --- js/src/table.ts | 2 +- js/test/unit/table-tests.ts | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/js/src/table.ts b/js/src/table.ts index d4fe5a93223d8..fdc61e2f1b77a 100644 --- a/js/src/table.ts +++ b/js/src/table.ts @@ -260,7 +260,7 @@ export class CountByResult extends Table implements DataFrame { super({batches: [[values, counts]]}); } - asJSON(): Object { + toJSON(): Object { let result: {[key: string]: number|null} = {}; for (let i = -1; ++i < this.length;) { diff --git a/js/test/unit/table-tests.ts b/js/test/unit/table-tests.ts index 2b818d7ff70ea..21da9d9acbea9 100644 --- a/js/test/unit/table-tests.ts +++ b/js/test/unit/table-tests.ts @@ -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, @@ -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, From 0126dc4d948a35dd6e4a530229e43925514bc9dd Mon Sep 17 00:00:00 2001 From: Brian Hulette Date: Wed, 17 Jan 2018 15:11:51 -0500 Subject: [PATCH 2/3] Don't recompute total length --- js/src/table.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/src/table.ts b/js/src/table.ts index fdc61e2f1b77a..42073fb9e0b22 100644 --- a/js/src/table.ts +++ b/js/src/table.ts @@ -115,7 +115,7 @@ export class Table implements DataFrame { } } count(): number { - return this.lengths.reduce((acc, val) => acc + val); + return this.length; } countBy(count_by: (Col|string)): CountByResult { if (!(count_by instanceof Col)) { From 0620cfdca70b44ca22ad002214410893d792ce16 Mon Sep 17 00:00:00 2001 From: Brian Hulette Date: Fri, 19 Jan 2018 16:57:36 -0500 Subject: [PATCH 3/3] use Math.fround --- js/test/unit/table-tests.ts | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/js/test/unit/table-tests.ts b/js/test/unit/table-tests.ts index 21da9d9acbea9..fb2d1593813b3 100644 --- a/js/test/unit/table-tests.ts +++ b/js/test/unit/table-tests.ts @@ -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); @@ -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);