Skip to content
Closed
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
15 changes: 14 additions & 1 deletion src/dataframe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use std::collections::HashMap;
use std::ffi::CString;
use std::sync::Arc;

use crate::datafusion_expr::Expr;
use arrow::array::{new_null_array, RecordBatch, RecordBatchIterator, RecordBatchReader};
use arrow::compute::can_cast_types;
use arrow::error::ArrowError;
Expand Down Expand Up @@ -473,7 +474,19 @@ impl PyDataFrame {
}

fn with_column(&self, name: &str, expr: PyExpr) -> PyDataFusionResult<Self> {
let df = self.df.as_ref().clone().with_column(name, expr.into())?;
let expr: Expr = expr.into();
let aliased = expr.alias(name);

let df_schema = self.df.as_ref().schema().clone();
let mut proj_exprs: Vec<Expr> = df_schema
.fields()
.iter()
.filter(|field| field.name() != name)
.map(|field| col(field.name()))
.collect();
proj_exprs.push(aliased);

let df = self.df.as_ref().clone().select(proj_exprs)?;
Ok(Self::new(df))
}

Expand Down
Loading