8000 Update test in browser for sortValues · javascriptdata/danfojs@06a5b51 · GitHub
[go: up one dir, main page]

Skip to content

Commit 06a5b51

Browse files
committed
Update test in browser for sortValues
1 parent b410f30 commit 06a5b51

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

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

Lines changed: 11 additions & 0 deletions
10000
Original file line numberDiff line numberDiff line change
@@ -1319,6 +1319,17 @@ describe("DataFrame", function () {
13191319
[ 6, 9 ] ];
13201320
assert.deepEqual(df.sortValues("A", { "ascending": true }).values, expected);
13211321
});
1322+
1323+
it("sort index in descending order and retains index", function () {
1324+
let data = [ [ 0, 2, 4, "b" ],
1325+
[ 360, 180, 360, "a" ],
1326+
[ 2, 4, 6, "c" ] ];
1327+
1328+
let df = new dfd.DataFrame(data, { "columns": [ "col1", "col2", "col3", "col4" ], index: [ "b", "a", "c" ] });
1329+
let df2 = df.sortIndex({ ascending: false });
1330+
let rslt = [ "c", "b", "a" ];
1331+
assert.deepEqual(df2.index, rslt);
1332+
});
13221333
});
13231334

13241335
describe("copy", function () {

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

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -688,6 +688,45 @@ describe("Series Functions", () => {
688688
const sortedSf = sf.sortValues({ ascending: false });
689689
assert.deepEqual(sortedSf.values, result);
690690
});
691+
692+
it("Index is retained after sort (ascending=true)", function () {
693+
let index = [ "apple", "banana", "orange", "grape" ];
694+
let value = [ 3, 6, 2, 9 ];
695+
696+
let sf = new dfd.Series(value, { index });
697+
sf.sortValues().print();
698+
const expectedValues = [ 2, 3, 6, 9 ];
699+
const expectedIndex = [ "orange", "apple", "banana", "grape" ];
700+
const sortedSf = sf.sortValues();
701+
assert.deepEqual(sortedSf.values, expectedValues);
702+
assert.deepEqual(sortedSf.index, expectedIndex);
703+
});
704+
it("Index is retained after sort (ascending=false)", function () {
705+
let index = [ "apple", "banana", "orange", "grape" ];
706+
let value = [ 3, 6, 2, 9 ];
707+
708+
let sf = new dfd.Series(value, { index });
709+
sf.sortValues().print();
710+
const expectedValues = [ 9, 6, 3, 2 ];
711+
const expectedIndex = [ "grape", "banana", "apple", "orange" ];
712+
const sortedSf = sf.sortValues({ ascending: false });
713+
assert.deepEqual(sortedSf.values, expectedValues);
714+
assert.deepEqual(sortedSf.index, expectedIndex);
715+
});
716+
717+
it("Index is retained after inplace sort (ascending=false)", function () {
718+
let index = [ "apple", "banana", "orange", "grape" ];
719+
let value = [ 3, 6, 2, 9 ];
720+
721+
let sf = new dfd.Series(value, { index });
722+
sf.sortValues().print();
723+
const expectedValues = [ 9, 6, 3, 2 ];
724+
const expectedIndex = [ "grape", "banana", "apple", "orange" ];
725+
sf.sortValues({ ascending: false, inplace: true });
726+
assert.deepEqual(sf.values, expectedValues);
727+
assert.deepEqual(sf.index, expectedIndex);
728+
});
729+
691730
});
692731

693732
describe("describe", function () {

0 commit comments

Comments
 (0)
0