From fd8333b3ecdac6ccddc1eb4c9e738f072c076f36 Mon Sep 17 00:00:00 2001 From: Iago <6860957+igonro@users.noreply.github.com> Date: Tue, 8 Mar 2022 12:56:02 +0100 Subject: [PATCH 1/4] Fix invalid assert.throws statements (issue #416); ToDo: tests not passing --- src/danfojs-browser/tests/core/frame.test.js | 8 +++----- src/danfojs-browser/tests/core/generic.test.js | 16 ++++++---------- src/danfojs-node/test/core/frame.test.ts | 8 +++----- src/danfojs-node/test/core/generic.test.ts | 16 ++++++---------- 4 files changed, 18 insertions(+), 30 deletions(-) diff --git a/src/danfojs-browser/tests/core/frame.test.js b/src/danfojs-browser/tests/core/frame.test.js index 9df80e54..bac39614 100644 --- a/src/danfojs-browser/tests/core/frame.test.js +++ b/src/danfojs-browser/tests/core/frame.test.js @@ -123,11 +123,9 @@ describe("DataFrame", function () { const data = { alpha: [ "A", "B", "C", "D" ], count: [ 1, 2, 3, 4 ], sum: [ 20.3, 30.456, 40.90, 90.1 ] }; const df = new dfd.DataFrame(data); - assert.throws(function () { - df.addColumn("new_column", new dfd.Series([ "a", "b", "c" ])), - Error, - 'ParamError: Column data length mismatch. You provided data with length 3 but Ndframe has column of length 4'; - }); + assert.throws( + () => df.addColumn("new_column", new dfd.Series([ "a", "b", "c" ])), Error, + 'ParamError: Column data length mismatch. You provided data with length 3 but Ndframe has column of length 4'); }); it("Ensure add column does not mutate parent when not in place", function () { diff --git a/src/danfojs-browser/tests/core/generic.test.js b/src/danfojs-browser/tests/core/generic.test.js index 44683e5a..60a8b515 100644 --- a/src/danfojs-browser/tests/core/generic.test.js +++ b/src/danfojs-browser/tests/core/generic.test.js @@ -59,20 +59,16 @@ describe("Generic (NDFrame)", function () { it("Throws error on duplicate column name", function () { let data = [ [ 21, 20, 1 ], [ 20, 25, 3 ] ]; - assert.throws(() => { - new dfd.NDframe({ data, isSeries: false, columns: [ "A", "A", "C" ] }), - Error, - "ColumnIndexError: Column index must contain unique values"; - }); + assert.throws( + () => new dfd.NDframe({ data, isSeries: false, columns: [ "A", "A", "C" ] }), Error, + "ColumnIndexError: Column index must contain unique values"); }); it("Throws error on duplicate index", function () { let data = [ [ 21, 20, 1 ], [ 20, 25, 3 ] ]; - assert.throws(() => { - new dfd.NDframe({ data, isSeries: false, index: [ 1, 1, 2 ] }), - Error, - "IndexError: Row index must contain unique values"; - }); + assert.throws( + () => new dfd.NDframe({ data, isSeries: false, index: [ 1, 1, 2 ] }), Error, + "IndexError: Row index must contain unique values"); }); it("Successfully create a 2D Frame when first value is empty", function () { diff --git a/src/danfojs-node/test/core/frame.test.ts b/src/danfojs-node/test/core/frame.test.ts index 8ed759bb..933e6366 100644 --- a/src/danfojs-node/test/core/frame.test.ts +++ b/src/danfojs-node/test/core/frame.test.ts @@ -128,11 +128,9 @@ describe("DataFrame", function () { const data = { alpha: ["A", "B", "C", "D"], val_count: [1, 2, 3, 4], val_sum: [20.3, 30.456, 40.90, 90.1] }; const df = new DataFrame(data); - assert.throws(function () { - df.addColumn("new_column", new Series(["a", "b", "c"])), - Error, - 'ParamError: Column data length mismatch. You provided data with length 3 but Ndframe has column of length 4' - }) + assert.throws( + () => df.addColumn("new_column", new Series(["a", "b", "c"])), Error, + 'ParamError: Column data length mismatch. You provided data with length 3 but Ndframe has column of length 4'); }); it("Ensure add column does not mutate parent when not in place", function () { diff --git a/src/danfojs-node/test/core/generic.test.ts b/src/danfojs-node/test/core/generic.test.ts index a7c390a0..2fe329f3 100644 --- a/src/danfojs-node/test/core/generic.test.ts +++ b/src/danfojs-node/test/core/generic.test.ts @@ -62,20 +62,16 @@ describe("Generic (NDFrame)", function () { it("Throws error on duplicate column name", function () { let data = [[21, 20, 1], [20, 25, 3]]; - assert.throws(() => { - new NDframe({ data, isSeries: false, columns: ["A", "A", "C"] }), - Error, - "ColumnIndexError: Column index must contain unique values" - }); + assert.throws( + () => new NDframe({ data, isSeries: false, columns: ["A", "A", "C"] }), Error, + "ColumnIndexError: Column index must contain unique values"); }); it("Throws error on duplicate index", function () { let data = [[21, 20, 1], [20, 25, 3]]; - assert.throws(() => { - new NDframe({ data, isSeries: false, index: [1, 1, 2] }), - Error, - "IndexError: Row index must contain unique values" - }); + assert.throws( + () => new NDframe({ data, isSeries: false, index: [1, 1, 2] }), Error, + "IndexError: Row index must contain unique values"); }); it("Successfully create a 2D Frame when first value is empty", function () { From 25ac3881d00db2147ef03fff4d2591a94feb449c Mon Sep 17 00:00:00 2001 From: Iago <6860957+igonro@users.noreply.github.com> Date: Tue, 8 Mar 2022 13:14:41 +0100 Subject: [PATCH 2/4] Fix throwColumnLengthError to take the right shape index --- src/danfojs-base/shared/errors.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/danfojs-base/shared/errors.ts b/src/danfojs-base/shared/errors.ts index cdd256d6..a433ab56 100644 --- a/src/danfojs-base/shared/errors.ts +++ b/src/danfojs-base/shared/errors.ts @@ -52,7 +52,7 @@ class ErrorThrower { } throwColumnLengthError = (ndframe: NDframe | DataFrame, arrLen: number): void => { - const msg = `ParamError: Column data length mismatch. You provided data with length ${arrLen} but Ndframe has column of length ${ndframe.shape[1]}` + const msg = `ParamError: Column data length mismatch. You provided data with length ${arrLen} but Ndframe has column of length ${ndframe.shape[0]}` throw new Error(msg) } From 57245944d1635162f43d388f24c03283e753b1da Mon Sep 17 00:00:00 2001 From: Iago <6860957+igonro@users.noreply.github.com> Date: Tue, 8 Mar 2022 13:15:15 +0100 Subject: [PATCH 3/4] Fix error on 'Throws error on duplicate index' tests --- src/danfojs-browser/tests/core/generic.test.js | 2 +- src/danfojs-node/test/core/generic.test.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/danfojs-browser/tests/core/generic.test.js b/src/danfojs-browser/tests/core/generic.test.js index 60a8b515..be37696c 100644 --- a/src/danfojs-browser/tests/core/generic.test.js +++ b/src/danfojs-browser/tests/core/generic.test.js @@ -65,7 +65,7 @@ describe("Generic (NDFrame)", function () { }); it("Throws error on duplicate index", function () { - let data = [ [ 21, 20, 1 ], [ 20, 25, 3 ] ]; + let data = [ [ 21, 20, 1 ], [ 20, 25, 3 ], [ 19, 30, 5 ] ]; assert.throws( () => new dfd.NDframe({ data, isSeries: false, index: [ 1, 1, 2 ] }), Error, "IndexError: Row index must contain unique values"); diff --git a/src/danfojs-node/test/core/generic.test.ts b/src/danfojs-node/test/core/generic.test.ts index 2fe329f3..e484067c 100644 --- a/src/danfojs-node/test/core/generic.test.ts +++ b/src/danfojs-node/test/core/generic.test.ts @@ -68,7 +68,7 @@ describe("Generic (NDFrame)", function () { }); it("Throws error on duplicate index", function () { - let data = [[21, 20, 1], [20, 25, 3]]; + let data = [[21, 20, 1], [20, 25, 3], [19, 30, 5]]; assert.throws( () => new NDframe({ data, isSeries: false, index: [1, 1, 2] }), Error, "IndexError: Row index must contain unique values"); From 12f79d331c17071a4e25777b1da1b2ec73631553 Mon Sep 17 00:00:00 2001 From: Iago <6860957+igonro@users.noreply.github.com> Date: Wed, 9 Mar 2022 14:18:51 +0100 Subject: [PATCH 4/4] Apply lint fix --- src/danfojs-browser/tests/core/frame.test.js | 6 ++++-- src/danfojs-browser/tests/core/generic.test.js | 12 ++++++++---- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/danfojs-browser/tests/core/frame.test.js b/src/danfojs-browser/tests/core/frame.test.js index bac39614..593c4e13 100644 --- a/src/danfojs-browser/tests/core/frame.test.js +++ b/src/danfojs-browser/tests/core/frame.test.js @@ -124,8 +124,10 @@ describe("DataFrame", function () { const df = new dfd.DataFrame(data); assert.throws( - () => df.addColumn("new_column", new dfd.Series([ "a", "b", "c" ])), Error, - 'ParamError: Column data length mismatch. You provided data with length 3 but Ndframe has column of length 4'); + () => df.addColumn("new_column", new dfd.Series([ "a", "b", "c" ])), + Error, + 'ParamError: Column data length mismatch. You provided data with length 3 but Ndframe has column of length 4' + ); }); it("Ensure add column does not mutate parent when not in place", function () { diff --git a/src/danfojs-browser/tests/core/generic.test.js b/src/danfojs-browser/tests/core/generic.test.js index be37696c..525ca2cb 100644 --- a/src/danfojs-browser/tests/core/generic.test.js +++ b/src/danfojs-browser/tests/core/generic.test.js @@ -60,15 +60,19 @@ describe("Generic (NDFrame)", function () { it("Throws error on duplicate column name", function () { let data = [ [ 21, 20, 1 ], [ 20, 25, 3 ] ]; assert.throws( - () => new dfd.NDframe({ data, isSeries: false, columns: [ "A", "A", "C" ] }), Error, - "ColumnIndexError: Column index must contain unique values"); + () => new dfd.NDframe({ data, isSeries: false, columns: [ "A", "A", "C" ] }), + Error, + "ColumnIndexError: Column index must contain unique values" + ); }); it("Throws error on duplicate index", function () { let data = [ [ 21, 20, 1 ], [ 20, 25, 3 ], [ 19, 30, 5 ] ]; assert.throws( - () => new dfd.NDframe({ data, isSeries: false, index: [ 1, 1, 2 ] }), Error, - "IndexError: Row index must contain unique values"); + () => new dfd.NDframe({ data, isSeries: false, index: [ 1, 1, 2 ] }), + Error, + "IndexError: Row index must contain unique values" + ); }); it("Successfully create a 2D Frame when first value is empty", function () {