From 3e53045d0e3bc735c731ef2281b5eda2ff54e90f Mon Sep 17 00:00:00 2001 From: librasteve Date: Mon, 2 Oct 2023 11:18:20 +0000 Subject: [PATCH] wip apply so --- apply/src/apply.rs | 55 +++------------------------------------------- 1 file changed, 3 insertions(+), 52 deletions(-) diff --git a/apply/src/apply.rs b/apply/src/apply.rs index 68118e6..b35610e 100644 --- a/apply/src/apply.rs +++ b/apply/src/apply.rs @@ -2,7 +2,7 @@ extern crate polars; use polars::prelude::*;//{CsvReader, DataType, DataFrame, Series}; use polars::lazy::dsl; -//use polars::lazy::dsl::Expr; +use polars::lazy::dsl::Expr; fn check_ptr<'a, T>(ptr: *mut T) -> &'a mut T { unsafe { @@ -54,8 +54,8 @@ pub extern "C" fn ap_apply_monadic(ptr: *mut ExprC) -> *mut ExprC { //START_APPLY - dyadic fn do_apply_dyadic(s: Series) -> Result, PolarsError> { - - println!("over------"); + let df = DataFrame::new(vec![s.clone()]); + println!("{:?}", &df); // downcast to struct let ca = s.struct_()?; @@ -88,55 +88,6 @@ fn do_apply_dyadic(s: Series) -> Result, PolarsError> { pub extern "C" fn ap_apply_dyadic(ptr: *mut ExprC) -> *mut ExprC { let ex_c = check_ptr(ptr); - let df = df!( - "values" => &[10, 7, 1], - "ovalues" => &[10, 7, 1], - ); - - println!("{:?}", df); - - let out = df.unwrap() - .lazy() - .select([ - // pack to struct to get access to multiple fields in a custom `apply/map` - as_struct(&[col("values"), col("ovalues")]) - .apply(do_apply_dyadic, GetOutput::default()) - /* - .apply( - |s| { - // downcast to struct - let ca = s.struct_()?; - - // get the fields as Series - let s_a = &ca.fields()[0]; - let s_b = &ca.fields()[1]; - - // downcast the `Series` to their known type - let ca_a = s_a.i32()?; - let ca_b = s_b.i32()?; - - // iterate both `ChunkedArrays` - let out: Int32Chunked = ca_a - .into_iter() - .zip(ca_b) - .map(|(opt_a, opt_b)| match (opt_a, opt_b) { - (Some(a), Some(b)) => Some(a + b), - _ => None, - }) - .collect(); - - Ok(Some(out.into_series())) - }, - GetOutput::default(), - //GetOutput::from_type(DataType::Int32), - ) - */ - .alias("solution_apply"), - ]) - .collect(); - println!("{}", out.unwrap()); - - let new_inn: Expr = ex_c.inner.clone().apply(do_apply_dyadic, GetOutput::default()).into(); let ex_n = ExprC::new(new_inn.clone());