Skip to content

Fix invalid assert.throws statements #419

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/danfojs-base/shared/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
8 changes: 4 additions & 4 deletions src/danfojs-browser/tests/core/frame.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,11 @@ 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" ])),
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';
});
'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 () {
Expand Down
18 changes: 9 additions & 9 deletions src/danfojs-browser/tests/core/generic.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,20 +59,20 @@ 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" ] }),
assert.throws(
() => new dfd.NDframe({ data, isSeries: false, columns: [ "A", "A", "C" ] }),
Error,
"ColumnIndexError: Column index must contain unique values";
});
"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 ] }),
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";
});
"IndexError: Row index must contain unique values"
);
});

it("Successfully create a 2D Frame when first value is empty", function () {
Expand Down
8 changes: 3 additions & 5 deletions src/danfojs-node/test/core/frame.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down
18 changes: 7 additions & 11 deletions src/danfojs-node/test/core/generic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
});
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");
});

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