ext/polars/src/lazy/dsl.rs in polars-df-0.1.3 vs ext/polars/src/lazy/dsl.rs in polars-df-0.1.4
- old
+ new
@@ -657,10 +657,69 @@
pub fn str_starts_with(&self, sub: String) -> Self {
self.inner.clone().str().starts_with(sub).into()
}
+ pub fn str_hex_encode(&self) -> Self {
+ self.clone()
+ .inner
+ .map(
+ move |s| s.utf8().map(|s| s.hex_encode().into_series()),
+ GetOutput::same_type(),
+ )
+ .with_fmt("str.hex_encode")
+ .into()
+ }
+
+ pub fn str_hex_decode(&self, strict: Option<bool>) -> Self {
+ self.clone()
+ .inner
+ .map(
+ move |s| s.utf8()?.hex_decode(strict).map(|s| s.into_series()),
+ GetOutput::same_type(),
+ )
+ .with_fmt("str.hex_decode")
+ .into()
+ }
+
+ pub fn str_base64_encode(&self) -> Self {
+ self.clone()
+ .inner
+ .map(
+ move |s| s.utf8().map(|s| s.base64_encode().into_series()),
+ GetOutput::same_type(),
+ )
+ .with_fmt("str.base64_encode")
+ .into()
+ }
+
+ pub fn str_base64_decode(&self, strict: Option<bool>) -> Self {
+ self.clone()
+ .inner
+ .map(
+ move |s| s.utf8()?.base64_decode(strict).map(|s| s.into_series()),
+ GetOutput::same_type(),
+ )
+ .with_fmt("str.base64_decode")
+ .into()
+ }
+
+ pub fn str_json_path_match(&self, pat: String) -> Self {
+ let function = move |s: Series| {
+ let ca = s.utf8()?;
+ match ca.json_path_match(&pat) {
+ Ok(ca) => Ok(ca.into_series()),
+ Err(e) => Err(PolarsError::ComputeError(format!("{:?}", e).into())),
+ }
+ };
+ self.clone()
+ .inner
+ .map(function, GetOutput::from_type(DataType::Utf8))
+ .with_fmt("str.json_path_match")
+ .into()
+ }
+
pub fn str_extract(&self, pat: String, group_index: usize) -> Self {
self.inner.clone().str().extract(&pat, group_index).into()
}
pub fn str_extract_all(&self, pat: String) -> Self {
@@ -885,10 +944,14 @@
pub fn dt_round(&self, every: String, offset: String) -> Self {
self.inner.clone().dt().round(&every, &offset).into()
}
+ pub fn dot(&self, other: &RbExpr) -> Self {
+ self.inner.clone().dot(other.inner.clone()).into()
+ }
+
pub fn reinterpret(&self, signed: bool) -> Self {
let function = move |s: Series| reinterpret(&s, signed);
let dt = if signed {
DataType::Int64
} else {
@@ -1206,10 +1269,32 @@
.clone()
.cumulative_eval(expr.inner.clone(), min_periods, parallel)
.into()
}
+ pub fn lst_to_struct(
+ &self,
+ width_strat: Wrap<ListToStructWidthStrategy>,
+ _name_gen: Option<Value>,
+ ) -> RbResult<Self> {
+ // TODO fix
+ let name_gen = None;
+ // let name_gen = name_gen.map(|lambda| {
+ // Arc::new(move |idx: usize| {
+ // let out: Value = lambda.funcall("call", (idx,)).unwrap();
+ // out.try_convert::<String>().unwrap()
+ // }) as NameGenerator
+ // });
+
+ Ok(self
+ .inner
+ .clone()
+ .arr()
+ .to_struct(width_strat.0, name_gen)
+ .into())
+ }
+
pub fn rank(&self, method: Wrap<RankMethod>, reverse: bool) -> Self {
let options = RankOptions {
method: method.0,
descending: reverse,
};
@@ -1429,9 +1514,22 @@
if value.is_nil() {
Ok(polars::lazy::dsl::repeat(Null {}, n_times.inner.clone()).into())
} else {
todo!();
}
+}
+
+pub fn pearson_corr(a: &RbExpr, b: &RbExpr, ddof: u8) -> RbExpr {
+ polars::lazy::dsl::pearson_corr(a.inner.clone(), b.inner.clone(), ddof).into()
+}
+
+pub fn spearman_rank_corr(a: &RbExpr, b: &RbExpr, ddof: u8, propagate_nans: bool) -> RbExpr {
+ polars::lazy::dsl::spearman_rank_corr(a.inner.clone(), b.inner.clone(), ddof, propagate_nans)
+ .into()
+}
+
+pub fn cov(a: &RbExpr, b: &RbExpr) -> RbExpr {
+ polars::lazy::dsl::cov(a.inner.clone(), b.inner.clone()).into()
}
#[magnus::wrap(class = "Polars::RbWhen")]
#[derive(Clone)]
pub struct RbWhen {