Skip to content

Commit 08ced18

Browse files
committed
test!: tests work, but are broken
Floating points are weird in JS. Will likely need refactor to make tests pass since _functionally_ they work.
1 parent aa61093 commit 08ced18

1 file changed

Lines changed: 11 additions & 11 deletions

File tree

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1037,48 +1037,48 @@ describe("DataFrame", function () {
10371037
});
10381038
});
10391039

1040-
describe("pct_change", function () {
1040+
describe("pctChange", function () {
10411041
it("Return same DataFrame if other === 0", function () {
10421042
const data = [[0, 2, 4], [10, 10, 10], [1, 2, 3]];
10431043
const df = new DataFrame(data);
1044-
assert.deepEqual((df.pct_change(0) as DataFrame).values, [[0, 2, 4], [10, 10, 10], [1, 2, 3]]);
1044+
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 () {
10471047
const data = [[90], [91], [85]];
10481048
const df = new DataFrame(data);
1049-
assert.deepEqual((df.pct_change(1) as DataFrame).values, [[NaN], [0.011111], [-0.065934]]);
1049+
assert.deepEqual((df.pctChange(1) as DataFrame).values, [[NaN], [((91 / 90) - 1)], [((85 / 91) - 1)]]);
10501050
});
10511051
it("Return difference in percentage of DataFrame with following row", function () {
10521052
const data = [[0, 2, 4], [10, 10, 10], [1, 2, 3]];
10531053
const df = new DataFrame(data);
1054-
assert.deepEqual((df.pct_change(-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.8, -0.6], [9, 4, 2.333333], [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]];
10581058
const sf = new Series([1, 2, 1]);
10591059
const df = new DataFrame(data);
1060-
assert.deepEqual((df.pct_change(sf) as DataFrame).values, [[-1, 0, 3], [9, 4, 9], [0, 0, 2]]);
1060+
assert.deepEqual((df.pctChange(sf) as DataFrame).values, [[-1, 0, 3], [9, 4, 9], [0, 0, 2]]);
10611061
});
10621062
it("Return difference in percentage of a DataFrame with along axis 0 (column-wise), previous column", function () {
10631063
const data = [[0, 2, 4], [10, 10, 10], [1, 2, 3]];
10641064
const df = new DataFrame(data);
1065-
assert.deepEqual((df.pct_change(1, { axis: 0 }) as DataFrame).values, [[NaN, -1, 1], [NaN, 0, 0], [NaN, 1, 0.5]]);
1065+
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 () {
10681068
const data = [[0, 2, 4], [10, 10, 10], [1, 2, 3]];
10691069
const df = new DataFrame(data);
1070-
assert.deepEqual((df.pct_change(-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.333333, 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]]);
10741074
const df2 = new DataFrame([[-1, -2, 4], [10, 5, 0]]);
1075-
assert.deepEqual((df1.pct_change(df2) as DataFrame).values, [[-1, -2, 0], [-0.7, 1, -1]]);
1075+
assert.deepEqual((df1.pctChange(df2) as DataFrame).values, [[-1, -2, 0], [-0.7, 1, -1]]);
10761076
});
1077-
it("Throw error if DataFrame for pct_change contains string", function () {
1077+
it("Throw error if DataFrame for pctChange contains string", function () {
10781078
const df = new DataFrame([["words", "words", "words"], ["words", "words", "words"]]);
10791079
assert.throws(() => {
1080-
df.pct_change(1);
1081-
}, Error, "TypeError: pct_change operation is not supported for string dtypes");
1080+
df.pctChange(1);
1081+
}, Error, "TypeError: pctChange operation is not supported for string dtypes");
10821082
});
10831083
});
10841084

0 commit comments

Comments
 (0)