Skip to content

Commit

Permalink
update pivot on to first pos argument
Browse files Browse the repository at this point in the history
  • Loading branch information
b-twice committed Aug 10, 2024
1 parent 95191df commit d9b9b4c
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
43 changes: 43 additions & 0 deletions __tests__/dataframe.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1354,6 +1354,49 @@ describe("dataframe", () => {
"e|b": [null, "y"],
});
expect(actual).toFrameEqual(expected, true);

df = pl.DataFrame({
foo: ["A", "A", "B", "B", "C"],
N: [1, 2, 2, 4, 2],
bar: ["k", "l", "m", "n", "o"],
});
actual = df.pivot(["N"], {
index: "foo",
on: "bar",
aggregateFunc: "first",
});
expected = pl.DataFrame({
foo: ["A", "B", "C"],
k: [1, null, null],
l: [2, null, null],
m: [null, 2, null],
n: [null, 4, null],
o: [null, null, 2],
});
expect(actual).toFrameEqual(expected, true);

df = pl.DataFrame({
ix: [1, 1, 2, 2, 1, 2],
col: ["a", "a", "a", "a", "b", "b"],
foo: [0, 1, 2, 2, 7, 1],
bar: [0, 2, 0, 0, 9, 4],
});

actual = df.pivot(["foo", "bar"], {
index: "ix",
on: "col",
aggregateFunc: "sum",
separator: "/",
});

expected = pl.DataFrame({
ix: [1, 2],
"foo/a": [1, 4],
"foo/b": [7, 1],
"bar/a": [2, 0],
"bar/b": [9, 4],
});
expect(actual).toFrameEqual(expected, true);
});
});
describe("join", () => {
Expand Down
2 changes: 1 addition & 1 deletion polars/dataframe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2237,8 +2237,8 @@ export const _DataFrame = (_df: any): DataFrame => {
return _DataFrame(
_df.pivotExpr(
values,
index,
on,
index,
fn,
maintainOrder,
sortColumns,
Expand Down

0 comments on commit d9b9b4c

Please sign in to comment.