#[cfg(feature = "dtype-struct")]
use polars_utils::pl_str::PlSmallStr;
use super::*;
pub struct ExprNameNameSpace(pub(crate) Expr);
impl ExprNameNameSpace {
pub fn keep(self) -> Expr {
Expr::KeepName(Arc::new(self.0))
}
pub fn map(self, function: PlanCallback<PlSmallStr, PlSmallStr>) -> Expr {
Expr::RenameAlias {
expr: Arc::new(self.0),
function: RenameAliasFn::Map(function),
}
}
pub fn prefix(self, prefix: &str) -> Expr {
Expr::RenameAlias {
expr: Arc::new(self.0),
function: RenameAliasFn::Prefix(prefix.into()),
}
}
pub fn suffix(self, suffix: &str) -> Expr {
Expr::RenameAlias {
expr: Arc::new(self.0),
function: RenameAliasFn::Suffix(suffix.into()),
}
}
#[cfg(feature = "regex")]
pub fn replace(self, pattern: &str, value: &str, literal: bool) -> Expr {
Expr::RenameAlias {
expr: Arc::new(self.0),
function: RenameAliasFn::Replace {
pattern: pattern.into(),
value: value.into(),
literal,
},
}
}
#[allow(clippy::wrong_self_convention)]
pub fn to_lowercase(self) -> Expr {
Expr::RenameAlias {
expr: Arc::new(self.0),
function: RenameAliasFn::ToLowercase,
}
}
#[allow(clippy::wrong_self_convention)]
pub fn to_uppercase(self) -> Expr {
Expr::RenameAlias {
expr: Arc::new(self.0),
function: RenameAliasFn::ToUppercase,
}
}
#[cfg(feature = "dtype-struct")]
pub fn map_fields(self, function: PlanCallback<PlSmallStr, PlSmallStr>) -> Expr {
self.0
.map_unary(FunctionExpr::StructExpr(StructFunction::MapFieldNames(
function,
)))
}
#[cfg(feature = "dtype-struct")]
pub fn prefix_fields(self, prefix: &str) -> Expr {
self.0
.map_unary(FunctionExpr::StructExpr(StructFunction::PrefixFields(
PlSmallStr::from_str(prefix),
)))
}
#[cfg(feature = "dtype-struct")]
pub fn suffix_fields(self, suffix: &str) -> Expr {
self.0
.map_unary(FunctionExpr::StructExpr(StructFunction::SuffixFields(
PlSmallStr::from_str(suffix),
)))
}
}
#[cfg(feature = "dtype-struct")]
pub type FieldsNameMapper = Arc<dyn Fn(&str) -> PlSmallStr + Send + Sync>;