ext/polars/src/lazy/dsl.rs in polars-df-0.1.4 vs ext/polars/src/lazy/dsl.rs in polars-df-0.1.5

- old
+ new

@@ -1,5 +1,6 @@ +use magnus::block::Proc; use magnus::{class, RArray, RString, Value}; use polars::chunked_array::ops::SortOptions; use polars::lazy::dsl; use polars::lazy::dsl::Operator; use polars::prelude::*; @@ -944,10 +945,14 @@ pub fn dt_round(&self, every: String, offset: String) -> Self { self.inner.clone().dt().round(&every, &offset).into() } + pub fn map(&self, lambda: Value, output_type: Option<Wrap<DataType>>, agg_list: bool) -> Self { + map_single(self, lambda, output_type, agg_list) + } + pub fn dot(&self, other: &RbExpr) -> Self { self.inner.clone().dot(other.inner.clone()).into() } pub fn reinterpret(&self, signed: bool) -> Self { @@ -977,10 +982,27 @@ pub fn suffix(&self, suffix: String) -> Self { self.inner.clone().suffix(&suffix).into() } + pub fn map_alias(&self, lambda: Proc) -> Self { + self.inner + .clone() + .map_alias(move |name| { + let out = lambda.call::<_, String>((name,)); + // TODO switch to match + out.unwrap() + // match out { + // Ok(out) => Ok(out.to_string()), + // Err(e) => Err(PolarsError::ComputeError( + // format!("Ruby function in 'map_alias' produced an error: {}.", e).into(), + // )), + // } + }) + .into() + } + pub fn exclude(&self, columns: Vec<String>) -> Self { self.inner.clone().exclude(columns).into() } pub fn interpolate(&self) -> Self { @@ -1448,10 +1470,14 @@ } pub fn entropy(&self, base: f64, normalize: bool) -> Self { self.inner.clone().entropy(base, normalize).into() } + + pub fn hash(&self, seed: u64, seed_1: u64, seed_2: u64, seed_3: u64) -> Self { + self.inner.clone().hash(seed, seed_1, seed_2, seed_3).into() + } } pub fn col(name: String) -> RbExpr { dsl::col(&name).into() } @@ -1477,10 +1503,17 @@ let func = move |a: Series, b: Series| binary_lambda(lambda, a, b); Ok(polars::lazy::dsl::fold_exprs(acc.inner.clone(), func, exprs).into()) } +pub fn cumfold(acc: &RbExpr, lambda: Value, exprs: RArray, include_init: bool) -> 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::cumfold_exprs(acc.inner.clone(), func, exprs, include_init).into()) +} + // TODO improve pub fn lit(value: Value) -> RbResult<RbExpr> { if value.is_nil() { Ok(dsl::lit(Null {}).into()) } else if let Ok(series) = value.try_convert::<&RbSeries>() { @@ -1527,9 +1560,14 @@ .into() } pub fn cov(a: &RbExpr, b: &RbExpr) -> RbExpr { polars::lazy::dsl::cov(a.inner.clone(), b.inner.clone()).into() +} + +pub fn argsort_by(by: RArray, reverse: Vec<bool>) -> RbResult<RbExpr> { + let by = rb_exprs_to_exprs(by)?; + Ok(polars::lazy::dsl::argsort_by(by, &reverse).into()) } #[magnus::wrap(class = "Polars::RbWhen")] #[derive(Clone)] pub struct RbWhen {