Skip to content

Commit b77662d

Browse files
authored
Merge pull request #419 from igonro/i416-fix-assert-throws-statements
Fix invalid assert.throws statements
2 parents 92ca12d + 12f79d3 commit b77662d

5 files changed

Lines changed: 24 additions & 30 deletions

File tree

src/danfojs-base/shared/errors.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class ErrorThrower {
5757
}
5858

5959
throwColumnLengthError = (ndframe: NDframe | DataFrame, arrLen: number): void => {
60-
const msg = `ParamError: Column data length mismatch. You provided data with length ${arrLen} but Ndframe has column of length ${ndframe.shape[1]}`
60+
const msg = `ParamError: Column data length mismatch. You provided data with length ${arrLen} but Ndframe has column of length ${ndframe.shape[0]}`
6161
throw new Error(msg)
6262
}
6363

src/danfojs-browser/tests/core/frame.test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,11 @@ describe("DataFrame", function () {
123123
const data = { alpha: [ "A", "B", "C", "D" ], count: [ 1, 2, 3, 4 ], sum: [ 20.3, 30.456, 40.90, 90.1 ] };
124124
const df = new dfd.DataFrame(data);
125125

126-
assert.throws(function () {
127-
df.addColumn("new_column", new dfd.Series([ "a", "b", "c" ])),
126+
assert.throws(
127+
() => df.addColumn("new_column", new dfd.Series([ "a", "b", "c" ])),
128128
Error,
129-
'ParamError: Column data length mismatch. You provided data with length 3 but Ndframe has column of length 4';
130-
});
129+
'ParamError: Column data length mismatch. You provided data with length 3 but Ndframe has column of length 4'
130+
);
131131

132132
});
133133
it("Ensure add column does not mutate parent when not in place", function () {

src/danfojs-browser/tests/core/generic.test.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,20 +59,20 @@ describe("Generic (NDFrame)", function () {
5959

6060
it("Throws error on duplicate column name", function () {
6161
let data = [ [ 21, 20, 1 ], [ 20, 25, 3 ] ];
62-
assert.throws(() => {
63-
new dfd.NDframe({ data, isSeries: false, columns: [ "A", "A", "C" ] }),
62+
assert.throws(
63+
() => new dfd.NDframe({ data, isSeries: false, columns: [ "A", "A", "C" ] }),
6464
Error,
65-
"ColumnIndexError: Column index must contain unique values";
66-
});
65+
"ColumnIndexError: Column index must contain unique values"
66+
);
6767
});
6868

6969
it("Throws error on duplicate index", function () {
70-
let data = [ [ 21, 20, 1 ], [ 20, 25, 3 ] ];
71-
assert.throws(() => {
72-
new dfd.NDframe({ data, isSeries: false, index: [ 1, 1, 2 ] }),
70+
let data = [ [ 21, 20, 1 ], [ 20, 25, 3 ], [ 19, 30, 5 ] ];
71+
assert.throws(
72+
() => new dfd.NDframe({ data, isSeries: false, index: [ 1, 1, 2 ] }),
7373
Error,
74-
"IndexError: Row index must contain unique values";
75-
});
74+
"IndexError: Row index must contain unique values"
75+
);
7676
});
7777

7878
it("Successfully create a 2D Frame when first value is empty", function () {

src/danfojs-node/test/core/frame.test.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -128,11 +128,9 @@ describe("DataFrame", function () {
128128
const data = { alpha: ["A", "B", "C", "D"], val_count: [1, 2, 3, 4], val_sum: [20.3, 30.456, 40.90, 90.1] };
129129
const df = new DataFrame(data);
130130

131-
assert.throws(function () {
132-
df.addColumn("new_column", new Series(["a", "b", "c"])),
133-
Error,
134-
'ParamError: Column data length mismatch. You provided data with length 3 but Ndframe has column of length 4'
135-
})
131+
assert.throws(
132+
() => df.addColumn("new_column", new Series(["a", "b", "c"])), Error,
133+
'ParamError: Column data length mismatch. You provided data with length 3 but Ndframe has column of length 4');
136134

137135
});
138136
it("Ensure add column does not mutate parent when not in place", function () {

src/danfojs-node/test/core/generic.test.ts

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -62,20 +62,16 @@ describe("Generic (NDFrame)", function () {
6262

6363
it("Throws error on duplicate column name", function () {
6464
let data = [[21, 20, 1], [20, 25, 3]];
65-
assert.throws(() => {
66-
new NDframe({ data, isSeries: false, columns: ["A", "A", "C"] }),
67-
Error,
68-
"ColumnIndexError: Column index must contain unique values"
69-
});
65+
assert.throws(
66+
() => new NDframe({ data, isSeries: false, columns: ["A", "A", "C"] }), Error,
67+
"ColumnIndexError: Column index must contain unique values");
7068
});
7169

7270
it("Throws error on duplicate index", function () {
73-
let data = [[21, 20, 1], [20, 25, 3]];
74-
assert.throws(() => {
75-
new NDframe({ data, isSeries: false, index: [1, 1, 2] }),
76-
Error,
77-
"IndexError: Row index must contain unique values"
78-
});
71+
let data = [[21, 20, 1], [20, 25, 3], [19, 30, 5]];
72+
assert.throws(
73+
() => new NDframe({ data, isSeries: false, index: [1, 1, 2] }), Error,
74+
"IndexError: Row index must contain unique values");
7975
});
8076

8177
it("Successfully create a 2D Frame when first value is empty", function () {

0 commit comments

Comments
 (0)