Skip to content

Commit 875b1ab

Browse files
authored
Merge pull request #3196 from perspective-dev/fix-to-columns-hidden-sort
Fix `to_columns` off-by-one serialization error
2 parents 64a4157 + 6bd3c92 commit 875b1ab

2 files changed

Lines changed: 55 additions & 1 deletion

File tree

rust/perspective-js/test/js/sort.spec.js

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,60 @@ const data3 = {
540540
table.delete();
541541
});
542542

543+
test("group by with multiple hidden sorts emits all visible columns in to_columns()", async function () {
544+
// https://github.com/perspective-dev/perspective/issues/3195
545+
const table = await perspective.table({
546+
v1: [1, 2, 3, 4],
547+
v2: [10, 20, 30, 40],
548+
v3: [100, 200, 300, 400],
549+
h1: [1.5, 2.5, 3.5, 4.5],
550+
h2: [4.5, 3.5, 2.5, 1.5],
551+
g: ["a", "a", "b", "b"],
552+
});
553+
const view = await table.view({
554+
columns: ["v1", "v2", "v3"],
555+
group_by: ["g"],
556+
sort: [
557+
["h1", "desc"],
558+
["h2", "desc"],
559+
],
560+
});
561+
const result = await view.to_columns();
562+
expect(result).toEqual({
563+
__ROW_PATH__: [[], ["b"], ["a"]],
564+
v1: [10, 7, 3],
565+
v2: [100, 70, 30],
566+
v3: [1000, 700, 300],
567+
});
568+
view.delete();
569+
table.delete();
570+
});
571+
572+
test("group by with more hidden sorts than visible columns does not emit hidden columns in to_columns()", async function () {
573+
// https://github.com/perspective-dev/perspective/issues/3195
574+
const table = await perspective.table({
575+
v1: [1, 2, 3, 4],
576+
h1: [1.5, 2.5, 3.5, 4.5],
577+
h2: [4.5, 3.5, 2.5, 1.5],
578+
g: ["a", "a", "b", "b"],
579+
});
580+
const view = await table.view({
581+
columns: ["v1"],
582+
group_by: ["g"],
583+
sort: [
584+
["h1", "desc"],
585+
["h2", "desc"],
586+
],
587+
});
588+
const result = await view.to_columns();
589+
expect(result).toEqual({
590+
__ROW_PATH__: [[], ["b"], ["a"]],
591+
v1: [10, 7, 3],
592+
});
593+
view.delete();
594+
table.delete();
595+
});
596+
543597
test("split by ['y']", async function () {
544598
const table = await perspective.table(data);
545599
const view = await table.view({

rust/perspective-server/cpp/perspective/src/cpp/view.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2702,7 +2702,7 @@ View<t_ctx1>::to_columns(
27022702
// Hidden columns are always at the end of the column names
27032703
// list, and we need to skip them from the output.
27042704
for (auto c = start_col + 1; c < end_col; ++c) {
2705-
if ((c - 1) > columns_length - hidden) {
2705+
if ((c - 1) >= columns_length) {
27062706
continue;
27072707
}
27082708
write_column(

0 commit comments

Comments
 (0)