Skip to content

Commit

Permalink
wip apply so
Browse files Browse the repository at this point in the history
  • Loading branch information
librasteve committed Oct 2, 2023
1 parent 0c58c91 commit 3e53045
Showing 1 changed file with 3 additions and 52 deletions.
55 changes: 3 additions & 52 deletions apply/src/apply.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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<Option<Series>, PolarsError> {


println!("over------");
let df = DataFrame::new(vec![s.clone()]);
println!("{:?}", &df);

// downcast to struct
let ca = s.struct_()?;
Expand Down Expand Up @@ -88,55 +88,6 @@ fn do_apply_dyadic(s: Series) -> Result<Option<Series>, 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());
Expand Down

0 comments on commit 3e53045

Please sign in to comment.