Skip to content

Commit 0ee424c

Browse files
authored
Merge pull request #422 from NeonSpork/test-patch
test: Added missing unit tests for `diff()` and `pctChange()`
2 parents f49f16c + 00ece4b commit 0ee424c

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1040,6 +1040,12 @@ describe("DataFrame", function () {
10401040
const df = new dfd.DataFrame(data);
10411041
assert.deepEqual((df.pctChange(sf)).values, [ [ -1, 0, 3 ], [ 9, 4, 9 ], [ 0, 0, 2 ] ]);
10421042
});
1043+
it("Return difference in percentage of a DataFrame with a Series along axis 0", function () {
1044+
const data = [ [ 0, 2, 4 ], [ 10, 10, 10 ], [ 1, 2, 3 ] ];
1045+
const sf = new dfd.Series([ 1, 2, 1 ]);
1046+
const df = new dfd.DataFrame(data);
1047+
assert.deepEqual((df.pctChange(sf, { axis: 0 })).values, [ [ -1, 1, 3 ], [ 4, 4, 4 ], [ 0, 1, 2 ] ]);
1048+
});
10431049
it("Return difference in percentage of a DataFrame with along axis 0 (column-wise), previous column", function () {
10441050
const data = [ [ 0, 2, 4 ], [ 10, 10, 10 ], [ 1, 2, 3 ] ];
10451051
const df = new dfd.DataFrame(data);
@@ -1085,6 +1091,12 @@ describe("DataFrame", function () {
10851091
const df = new dfd.DataFrame(data);
10861092
assert.deepEqual((df.diff(sf)).values, [ [ -1, 0, 3 ], [ 9, 8, 9 ], [ 0, 0, 2 ] ]);
10871093
});
1094+
it("Return difference of a DataFrame with a Series along axis 0", function () {
1095+
const data = [ [ 0, 2, 4 ], [ 10, 10, 10 ], [ 1, 2, 3 ] ];
1096+
const sf = new dfd.Series([ 1, 2, 1 ]);
1097+
const df = new dfd.DataFrame(data);
1098+
assert.deepEqual((df.diff(sf, { axis: 0 })).values, [ [ -1, 1, 3 ], [ 8, 8, 8 ], [ 0, 1, 2 ] ]);
1099+
});
10881100
it("Return difference of a DataFrame with along axis 0 (column-wise), previous column", function () {
10891101
const data = [ [ 0, 2, 4 ], [ 10, 10, 10 ], [ 1, 2, 3 ] ];
10901102
const df = new dfd.DataFrame(data);

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1014,6 +1014,12 @@ describe("DataFrame", function () {
10141014
const df = new DataFrame(data);
10151015
assert.deepEqual((df.diff(sf) as DataFrame).values, [[-1, 0, 3], [9, 8, 9], [0, 0, 2]]);
10161016
});
1017+
it("Return difference of a DataFrame with a Series along axis 0", function () {
1018+
const data = [[0, 2, 4], [10, 10, 10], [1, 2, 3]];
1019+
const sf = new Series([1, 2, 1]);
1020+
const df = new DataFrame(data);
1021+
assert.deepEqual((df.diff(sf, {axis: 0}) as DataFrame).values, [[-1, 1, 3], [8, 8, 8], [0, 1, 2]]);
1022+
});
10171023
it("Return difference of a DataFrame with along axis 0 (column-wise), previous column", function () {
10181024
const data = [[0, 2, 4], [10, 10, 10], [1, 2, 3]];
10191025
const df = new DataFrame(data);
@@ -1059,6 +1065,12 @@ describe("DataFrame", function () {
10591065
const df = new DataFrame(data);
10601066
assert.deepEqual((df.pctChange(sf) as DataFrame).values, [[-1, 0, 3], [9, 4, 9], [0, 0, 2]]);
10611067
});
1068+
it("Return difference in percentage of a DataFrame with a Series along axis 0", function () {
1069+
const data = [[0, 2, 4], [10, 10, 10], [1, 2, 3]];
1070+
const sf = new Series([1, 2, 1]);
1071+
const df = new DataFrame(data);
1072+
assert.deepEqual((df.pctChange(sf, {axis: 0})).values, [[-1, 1, 3], [4, 4, 4], [0, 1, 2]]);
1073+
});
10621074
it("Return difference in percentage of a DataFrame with along axis 0 (column-wise), previous column", function () {
10631075
const data = [[0, 2, 4], [10, 10, 10], [1, 2, 3]];
10641076
const df = new DataFrame(data);

0 commit comments

Comments
 (0)