Skip to content

Commit 571cb23

Browse files
timsaucerclaude
andcommitted
Merge union_by_name and union_by_name_distinct into a single method with distinct flag
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 385da6c commit 571cb23

File tree

2 files changed

+10
-19
lines changed

2 files changed

+10
-19
lines changed

crates/core/src/dataframe.rs

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -971,22 +971,15 @@ impl PyDataFrame {
971971
}
972972

973973
/// Union two DataFrames matching columns by name
974-
fn union_by_name(&self, py_df: PyDataFrame) -> PyDataFusionResult<Self> {
975-
let new_df = self
976-
.df
977-
.as_ref()
978-
.clone()
979-
.union_by_name(py_df.df.as_ref().clone())?;
980-
Ok(Self::new(new_df))
981-
}
982-
983-
/// Union two DataFrames by name with deduplication
984-
fn union_by_name_distinct(&self, py_df: PyDataFrame) -> PyDataFusionResult<Self> {
985-
let new_df = self
986-
.df
987-
.as_ref()
988-
.clone()
989-
.union_by_name_distinct(py_df.df.as_ref().clone())?;
974+
#[pyo3(signature = (py_df, distinct=false))]
975+
fn union_by_name(&self, py_df: PyDataFrame, distinct: bool) -> PyDataFusionResult<Self> {
976+
let base = self.df.as_ref().clone();
977+
let other = py_df.df.as_ref().clone();
978+
let new_df = if distinct {
979+
base.union_by_name_distinct(other)?
980+
} else {
981+
base.union_by_name(other)?
982+
};
990983
Ok(Self::new(new_df))
991984
}
992985

python/datafusion/dataframe.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1300,9 +1300,7 @@ def union_by_name(self, other: DataFrame, distinct: bool = False) -> DataFrame:
13001300
>>> df1.union_by_name(df2, distinct=True).to_pydict()
13011301
{'a': [1], 'b': [10]}
13021302
"""
1303-
if distinct:
1304-
return DataFrame(self.df.union_by_name_distinct(other.df))
1305-
return DataFrame(self.df.union_by_name(other.df))
1303+
return DataFrame(self.df.union_by_name(other.df, distinct))
13061304

13071305
def distinct_on(
13081306
self,

0 commit comments

Comments
 (0)