From c1286b1c3fc04e571f40aaeba63f551bf1ee4a72 Mon Sep 17 00:00:00 2001 From: ritchie Date: Mon, 29 Apr 2024 12:18:31 +0200 Subject: [PATCH] fix tests --- crates/polars-lazy/src/frame/mod.rs | 2 +- crates/polars-ops/src/frame/join/args.rs | 13 +++++++++++++ crates/polars-ops/src/frame/join/mod.rs | 8 +++----- crates/polars-plan/src/logical_plan/schema.rs | 9 ++++++--- 4 files changed, 23 insertions(+), 9 deletions(-) diff --git a/crates/polars-lazy/src/frame/mod.rs b/crates/polars-lazy/src/frame/mod.rs index 47d2652609db..b464567066e4 100644 --- a/crates/polars-lazy/src/frame/mod.rs +++ b/crates/polars-lazy/src/frame/mod.rs @@ -1874,7 +1874,7 @@ impl JoinBuilder { suffix: self.suffix, slice: None, join_nulls: self.join_nulls, - ..Default::default() + coalesce: self.coalesce, }; let lp = self diff --git a/crates/polars-ops/src/frame/join/args.rs b/crates/polars-ops/src/frame/join/args.rs index 8b4bb6b7cb27..148c46ce7953 100644 --- a/crates/polars-ops/src/frame/join/args.rs +++ b/crates/polars-ops/src/frame/join/args.rs @@ -139,6 +139,19 @@ impl Debug for JoinType { } } +impl JoinType { + pub fn is_asof(&self) -> bool { + #[cfg(feature = "asof_join")] + { + matches!(self, JoinType::AsOf(_)) + } + #[cfg(not(feature = "asof_join"))] + { + false + } + } +} + #[derive(Copy, Clone, PartialEq, Eq, Default, Hash)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub enum JoinValidation { diff --git a/crates/polars-ops/src/frame/join/mod.rs b/crates/polars-ops/src/frame/join/mod.rs index d8b87930a91c..6a29e2b28c3a 100644 --- a/crates/polars-ops/src/frame/join/mod.rs +++ b/crates/polars-ops/src/frame/join/mod.rs @@ -209,9 +209,7 @@ pub trait DataFrameJoinOps: IntoDf { JoinType::Left => { left_df._left_join_from_series(other, s_left, s_right, args, _verbose, None) }, - JoinType::Outer { .. } => { - left_df._outer_join_from_series(other, s_left, s_right, args) - }, + JoinType::Outer => left_df._outer_join_from_series(other, s_left, s_right, args), #[cfg(feature = "semi_anti_join")] JoinType::Anti => left_df._semi_anti_join_from_series( s_left, @@ -278,14 +276,14 @@ pub trait DataFrameJoinOps: IntoDf { JoinType::Cross => { unreachable!() }, - JoinType::Outer => { + JoinType::Outer => { let names_left = selected_left.iter().map(|s| s.name()).collect::>(); let coalesce = args.coalesce; args.coalesce = JoinCoalesce::KeepColumns; let suffix = args.suffix.clone(); let out = left_df._outer_join_from_series(other, &lhs_keys, &rhs_keys, args); - if matches!(coalesce, JoinCoalesce::CoalesceColumns) { + if coalesce.coalesce(&JoinType::Outer) { Ok(_coalesce_outer_join( out?, &names_left, diff --git a/crates/polars-plan/src/logical_plan/schema.rs b/crates/polars-plan/src/logical_plan/schema.rs index ee7210184cd4..30ce626d1bf3 100644 --- a/crates/polars-plan/src/logical_plan/schema.rs +++ b/crates/polars-plan/src/logical_plan/schema.rs @@ -314,7 +314,7 @@ pub(crate) fn det_join_schema( arena.clear(); } let coalesces_join_keys = options.args.coalesce.coalesce(&options.args.how); - // except in asof joins. Asof joins are not equi-joins + // Except in asof joins. Asof joins are not equi-joins // so the columns that are joined on, may have different // values so if the right has a different name, it is added to the schema #[cfg(feature = "asof_join")] @@ -343,9 +343,12 @@ pub(crate) fn det_join_schema( join_on_right.insert(field.name); } + let are_coalesced = options.args.coalesce.coalesce(&options.args.how); + let is_asof = options.args.how.is_asof(); + + // Asof joins are special, if the names are equal they will not be coalesced. for (name, dtype) in schema_right.iter() { - if !coalesces_join_keys || // The names are not merged - !join_on_right.contains(name.as_str()) + if !join_on_right.contains(name.as_str()) || (!are_coalesced && !is_asof) // The names that are joined on are merged { if schema_left.contains(name.as_str()) {