ext/polars/src/lazy/dsl.rs in polars-df-0.1.1 vs ext/polars/src/lazy/dsl.rs in polars-df-0.1.2

- old
+ new

@@ -4,10 +4,11 @@ use polars::lazy::dsl::Operator; use polars::prelude::*; use polars::series::ops::NullBehavior; use crate::conversion::*; +use crate::lazy::apply::*; use crate::lazy::utils::rb_exprs_to_exprs; use crate::RbResult; #[magnus::wrap(class = "Polars::RbExpr")] #[derive(Clone)] @@ -899,10 +900,14 @@ pub fn suffix(&self, suffix: String) -> Self { self.inner.clone().suffix(&suffix).into() } + pub fn exclude(&self, columns: Vec<String>) -> Self { + self.inner.clone().exclude(columns).into() + } + pub fn interpolate(&self) -> Self { self.inner.clone().interpolate().into() } pub fn rolling_sum( @@ -1331,10 +1336,33 @@ pub fn col(name: String) -> RbExpr { dsl::col(&name).into() } +pub fn count() -> RbExpr { + dsl::count().into() +} + +pub fn first() -> RbExpr { + dsl::first().into() +} + +pub fn last() -> RbExpr { + dsl::last().into() +} + +pub fn cols(names: Vec<String>) -> RbExpr { + dsl::cols(names).into() +} + +pub fn fold(acc: &RbExpr, lambda: Value, exprs: RArray) -> RbResult<RbExpr> { + let exprs = rb_exprs_to_exprs(exprs)?; + + let func = move |a: Series, b: Series| binary_lambda(lambda, a, b); + Ok(polars::lazy::dsl::fold_exprs(acc.inner.clone(), func, exprs).into()) +} + // TODO improve pub fn lit(value: Value) -> RbResult<RbExpr> { if value.is_nil() { Ok(dsl::lit(Null {}).into()) } else if let Some(v) = RString::from_value(value) { @@ -1384,6 +1412,16 @@ } } pub fn when(predicate: &RbExpr) -> RbWhen { dsl::when(predicate.inner.clone()).into() +} + +pub fn concat_str(s: RArray, sep: String) -> RbResult<RbExpr> { + let s = rb_exprs_to_exprs(s)?; + Ok(dsl::concat_str(s, &sep).into()) +} + +pub fn concat_lst(s: RArray) -> RbResult<RbExpr> { + let s = rb_exprs_to_exprs(s)?; + Ok(dsl::concat_lst(s).into()) }