Skip to content

Commit 2c7d9dc

Browse files
committed
fix(test): worked around floating point division
Wonkiness of slight difference in calculation (`0.80000000001234` instead of `0.8` for example) is due to JavaScript. Functionally the tests worked, so I chose divisions that JavaScript does reliably.
1 parent 08ced18 commit 2c7d9dc

1 file changed

Lines changed: 8 additions & 8 deletions

File tree

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1044,14 +1044,14 @@ describe("DataFrame", function () {
10441044
assert.deepEqual((df.pctChange(0) as DataFrame).values, [[0, 2, 4], [10, 10, 10], [1, 2, 3]]);
10451045
});
10461046
it("Return difference in percentage of DataFrame with previous row", function () {
1047-
const data = [[90], [91], [85]];
1047+
const data = [[90], [900], [900]];
10481048
const df = new DataFrame(data);
1049-
assert.deepEqual((df.pctChange(1) as DataFrame).values, [[NaN], [((91 / 90) - 1)], [((85 / 91) - 1)]]);
1049+
assert.deepEqual((df.pctChange(1) as DataFrame).values, [[NaN], [9], [0]]);
10501050
});
10511051
it("Return difference in percentage of DataFrame with following row", function () {
1052-
const data = [[0, 2, 4], [10, 10, 10], [1, 2, 3]];
1052+
const data = [[0, 5, 15], [10, 10, 10], [1, 2, 5]];
10531053
const df = new DataFrame(data);
1054-
assert.deepEqual((df.pctChange(-1) as DataFrame).values, [[-1, -0.8, -0.6], [9, 4, 2.333333], [NaN, NaN, NaN]]);
1054+
assert.deepEqual((df.pctChange(-1) as DataFrame).values, [[-1, -0.5, 0.5], [9, 4, 1], [NaN, NaN, NaN]]);
10551055
});
10561056
it("Return difference in percentage of a DataFrame with a Series along default axis 1", function () {
10571057
const data = [[0, 2, 4], [10, 10, 10], [1, 2, 3]];
@@ -1065,14 +1065,14 @@ describe("DataFrame", function () {
10651065
assert.deepEqual((df.pctChange(1, { axis: 0 }) as DataFrame).values, [[NaN, -1, 1], [NaN, 0, 0], [NaN, 1, 0.5]]);
10661066
});
10671067
it("Return difference in percentage of a DataFrame with along axis 0 (column-wise), following column", function () {
1068-
const data = [[0, 2, 4], [10, 10, 10], [1, 2, 3]];
1068+
const data = [[0, 2, 4], [10, 10, 10], [1, 2, 8]];
10691069
const df = new DataFrame(data);
1070-
assert.deepEqual((df.pctChange(-1, { axis: 0 }) as DataFrame).values, [[-1, -0.5, NaN], [0, 0, NaN], [-0.5, -0.333333, NaN]]);
1070+
assert.deepEqual((df.pctChange(-1, { axis: 0 }) as DataFrame).values, [[-1, -0.5, NaN], [0, 0, NaN], [-0.5, -0.75, NaN]]);
10711071
});
10721072
it("Return difference in percentage of a DataFrame with another DataFrame along default axis 1", function () {
10731073
const df1 = new DataFrame([[0, 2, 4], [3, 10, 4]]);
1074-
const df2 = new DataFrame([[-1, -2, 4], [10, 5, 0]]);
1075-
assert.deepEqual((df1.pctChange(df2) as DataFrame).values, [[-1, -2, 0], [-0.7, 1, -1]]);
1074+
const df2 = new DataFrame([[-1, -2, 4], [6, 5, 0]]);
1075+
assert.deepEqual((df1.pctChange(df2) as DataFrame).values, [[-1, -2, 0], [-0.5, 1, -1]]);
10761076
});
10771077
it("Throw error if DataFrame for pctChange contains string", function () {
10781078
const df = new DataFrame([["words", "words", "words"], ["words", "words", "words"]]);

0 commit comments

Comments
 (0)