From 48b7d2bef780bccebe4aa3f4ef44da0f7b60a15f Mon Sep 17 00:00:00 2001 From: Bidek56 Date: Sat, 8 Jun 2024 19:59:54 -0400 Subject: [PATCH] adding JoinArgs --- __tests__/dataframe.test.ts | 4 ++-- polars/dataframe.ts | 3 +-- src/dataframe.rs | 9 ++++++++- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/__tests__/dataframe.test.ts b/__tests__/dataframe.test.ts index 3941b9414..4dfc46254 100644 --- a/__tests__/dataframe.test.ts +++ b/__tests__/dataframe.test.ts @@ -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); }); diff --git a/polars/dataframe.ts b/polars/dataframe.ts index 81ac27c83..4622fded5 100644 --- a/polars/dataframe.ts +++ b/polars/dataframe.ts @@ -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; @@ -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) { diff --git a/src/dataframe.rs b/src/dataframe.rs index 8a028454b..a03401971 100644 --- a/src/dataframe.rs +++ b/src/dataframe.rs @@ -577,6 +577,7 @@ impl JsDataFrame { left_on: Vec<&str>, right_on: Vec<&str>, how: String, + suffix: Option, ) -> napi::Result { let how = match how.as_ref() { "left" => JoinType::Left, @@ -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)) }