diff --git a/crates/polars-plan/Cargo.toml b/crates/polars-plan/Cargo.toml index d70a90914835..b4f920002745 100644 --- a/crates/polars-plan/Cargo.toml +++ b/crates/polars-plan/Cargo.toml @@ -147,6 +147,7 @@ peaks = ["polars-ops/peaks"] bigidx = ["polars-core/bigidx"] panic_on_schema = [] +lazy_regex = ["regex"] [package.metadata.docs.rs] all-features = true diff --git a/crates/polars-plan/src/dsl/function_expr/mod.rs b/crates/polars-plan/src/dsl/function_expr/mod.rs index 3ca6b5f2c7c9..fe3ee5c1de57 100644 --- a/crates/polars-plan/src/dsl/function_expr/mod.rs +++ b/crates/polars-plan/src/dsl/function_expr/mod.rs @@ -878,7 +878,7 @@ impl From for SpecialEq> { fn from(func: StringFunction) -> Self { use StringFunction::*; match func { - #[cfg(feature = "regex")] + #[cfg(feature = "lazy_regex")] Contains { literal, strict } => map_as_slice!(strings::contains, literal, strict), CountMatches(literal) => { map_as_slice!(strings::count_matches, literal) @@ -924,7 +924,7 @@ impl From for SpecialEq> { ConcatVertical(delimiter) => map!(strings::concat, &delimiter), #[cfg(feature = "concat_str")] ConcatHorizontal(delimiter) => map_as_slice!(strings::concat_hor, &delimiter), - #[cfg(feature = "regex")] + #[cfg(feature = "lazy_regex")] Replace { n, literal } => map_as_slice!(strings::replace, literal, n), Uppercase => map!(strings::uppercase), Lowercase => map!(strings::lowercase), diff --git a/crates/polars-plan/src/dsl/function_expr/strings.rs b/crates/polars-plan/src/dsl/function_expr/strings.rs index 4199475b787e..aa31406f084e 100644 --- a/crates/polars-plan/src/dsl/function_expr/strings.rs +++ b/crates/polars-plan/src/dsl/function_expr/strings.rs @@ -3,7 +3,7 @@ use std::borrow::Cow; use arrow::legacy::utils::CustomIterTools; #[cfg(feature = "timezones")] use once_cell::sync::Lazy; -#[cfg(feature = "regex")] +#[cfg(feature = "lazy_regex")] use regex::{escape, Regex}; #[cfg(feature = "serde")] use serde::{Deserialize, Serialize}; @@ -24,7 +24,7 @@ pub enum StringFunction { ConcatHorizontal(String), #[cfg(feature = "concat_str")] ConcatVertical(String), - #[cfg(feature = "regex")] + #[cfg(feature = "lazy_regex")] Contains { literal: bool, strict: bool, @@ -57,7 +57,7 @@ pub enum StringFunction { dtype: Option, infer_schema_len: Option, }, - #[cfg(feature = "regex")] + #[cfg(feature = "lazy_regex")] Replace { // negative is replace all // how many matches to replace @@ -101,7 +101,7 @@ impl StringFunction { match self { #[cfg(feature = "concat_str")] ConcatVertical(_) | ConcatHorizontal(_) => mapper.with_dtype(DataType::Utf8), - #[cfg(feature = "regex")] + #[cfg(feature = "lazy_regex")] Contains { .. } => mapper.with_dtype(DataType::Boolean), CountMatches(_) => mapper.with_dtype(DataType::UInt32), EndsWith | StartsWith => mapper.with_dtype(DataType::Boolean), @@ -116,7 +116,7 @@ impl StringFunction { JsonExtract { dtype, .. } => mapper.with_opt_dtype(dtype.clone()), LenBytes => mapper.with_dtype(DataType::UInt32), LenChars => mapper.with_dtype(DataType::UInt32), - #[cfg(feature = "regex")] + #[cfg(feature = "lazy_regex")] Replace { .. } => mapper.with_same_dtype(), #[cfg(feature = "temporal")] Strptime(dtype, _) => mapper.with_dtype(dtype.clone()), @@ -154,7 +154,7 @@ impl StringFunction { impl Display for StringFunction { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { let s = match self { - #[cfg(feature = "regex")] + #[cfg(feature = "lazy_regex")] StringFunction::Contains { .. } => "contains", StringFunction::CountMatches(_) => "count_matches", StringFunction::EndsWith { .. } => "ends_with", @@ -178,7 +178,7 @@ impl Display for StringFunction { StringFunction::LenChars => "len_chars", #[cfg(feature = "string_justify")] StringFunction::RJust { .. } => "rjust", - #[cfg(feature = "regex")] + #[cfg(feature = "lazy_regex")] StringFunction::Replace { .. } => "replace", StringFunction::Slice(_, _) => "slice", StringFunction::StartsWith { .. } => "starts_with", @@ -244,7 +244,7 @@ pub(super) fn len_bytes(s: &Series) -> PolarsResult { Ok(ca.str_len_bytes().into_series()) } -#[cfg(feature = "regex")] +#[cfg(feature = "lazy_regex")] pub(super) fn contains(s: &[Series], literal: bool, strict: bool) -> PolarsResult { let ca = s[0].utf8()?; let pat = s[1].utf8()?; @@ -569,7 +569,7 @@ impl From for FunctionExpr { } } -#[cfg(feature = "regex")] +#[cfg(feature = "lazy_regex")] fn get_pat(pat: &Utf8Chunked) -> PolarsResult<&str> { pat.get(0).ok_or_else( || polars_err!(ComputeError: "pattern cannot be 'null' in 'replace' expression"), @@ -595,12 +595,12 @@ where out } -#[cfg(feature = "regex")] +#[cfg(feature = "lazy_regex")] fn is_literal_pat(pat: &str) -> bool { pat.chars().all(|c| !c.is_ascii_punctuation()) } -#[cfg(feature = "regex")] +#[cfg(feature = "lazy_regex")] fn replace_n<'a>( ca: &'a Utf8Chunked, pat: &'a Utf8Chunked, @@ -661,7 +661,7 @@ fn replace_n<'a>( } } -#[cfg(feature = "regex")] +#[cfg(feature = "lazy_regex")] fn replace_all<'a>( ca: &'a Utf8Chunked, pat: &'a Utf8Chunked, @@ -706,7 +706,7 @@ fn replace_all<'a>( } } -#[cfg(feature = "regex")] +#[cfg(feature = "lazy_regex")] pub(super) fn replace(s: &[Series], literal: bool, n: i64) -> PolarsResult { let column = &s[0]; let pat = &s[1]; diff --git a/crates/polars-plan/src/dsl/string.rs b/crates/polars-plan/src/dsl/string.rs index 7e74806d7f31..196aca691475 100644 --- a/crates/polars-plan/src/dsl/string.rs +++ b/crates/polars-plan/src/dsl/string.rs @@ -5,7 +5,7 @@ pub struct StringNameSpace(pub(crate) Expr); impl StringNameSpace { /// Check if a string value contains a literal substring. - #[cfg(feature = "regex")] + #[cfg(feature = "lazy_regex")] pub fn contains_literal(self, pat: Expr) -> Expr { self.0.map_many_private( FunctionExpr::StringExpr(StringFunction::Contains { @@ -20,7 +20,7 @@ impl StringNameSpace { /// Check if this column of strings contains a Regex. If `strict` is `true`, then it is an error if any `pat` is /// an invalid regex, whereas if `strict` is `false`, an invalid regex will simply evaluate to `false`. - #[cfg(feature = "regex")] + #[cfg(feature = "lazy_regex")] pub fn contains(self, pat: Expr, strict: bool) -> Expr { self.0.map_many_private( FunctionExpr::StringExpr(StringFunction::Contains { @@ -258,7 +258,7 @@ impl StringNameSpace { .map_many_private(StringFunction::SplitN(n).into(), &[by], false, false) } - #[cfg(feature = "regex")] + #[cfg(feature = "lazy_regex")] /// Replace values that match a regex `pat` with a `value`. pub fn replace(self, pat: Expr, value: Expr, literal: bool) -> Expr { self.0.map_many_private( @@ -269,7 +269,7 @@ impl StringNameSpace { ) } - #[cfg(feature = "regex")] + #[cfg(feature = "lazy_regex")] /// Replace values that match a regex `pat` with a `value`. pub fn replace_n(self, pat: Expr, value: Expr, literal: bool, n: i64) -> Expr { self.0.map_many_private( @@ -280,7 +280,7 @@ impl StringNameSpace { ) } - #[cfg(feature = "regex")] + #[cfg(feature = "lazy_regex")] /// Replace all values that match a regex `pat` with a `value`. pub fn replace_all(self, pat: Expr, value: Expr, literal: bool) -> Expr { self.0.map_many_private(