Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding JoinArgs to fix join suffix #220

Merged
merged 1 commit into from
Jun 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions __tests__/dataframe.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1546,14 +1546,14 @@ describe("join", () => {
const actual = df.join(otherDF, {
on: "ham",
how: "left",
suffix: "_right",
suffix: "_other",
});
const expected = pl.DataFrame({
foo: [1, 2, 3],
bar: [6, 7, 8],
ham: ["a", "b", "c"],
apple: ["x", "y", null],
foo_right: [1, 10, null],
foo_other: [1, 10, null],
});
expect(actual).toFrameEqual(expected);
});
Expand Down
3 changes: 1 addition & 2 deletions polars/dataframe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2134,7 +2134,7 @@ export const _DataFrame = (_df: any): DataFrame => {
isEmpty: () => _df.height === 0,
isUnique: () => _Series(_df.isUnique()) as any,
join(other: DataFrame, options): DataFrame {
options = { how: "inner", suffix: "right", ...options };
options = { how: "inner", ...options };
const on = columnOrColumns(options.on);
const how = options.how;
const suffix = options.suffix;
Expand All @@ -2153,7 +2153,6 @@ export const _DataFrame = (_df: any): DataFrame => {
"You should pass the column to join on as an argument.",
);
}

return wrap("join", other._df, leftOn, rightOn, how, suffix);
},
joinAsof(other, options) {
Expand Down
9 changes: 8 additions & 1 deletion src/dataframe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,7 @@ impl JsDataFrame {
left_on: Vec<&str>,
right_on: Vec<&str>,
how: String,
suffix: Option<String>,
) -> napi::Result<JsDataFrame> {
let how = match how.as_ref() {
"left" => JoinType::Left,
Expand All @@ -597,7 +598,13 @@ impl JsDataFrame {

let df = self
.df
.join(&other.df, left_on, right_on, how.into())
.join(&other.df, left_on, right_on,
JoinArgs {
how: how,
suffix: suffix,
..Default::default()
}
)
.map_err(JsPolarsErr::from)?;
Ok(JsDataFrame::new(df))
}
Expand Down