Skip to content

Commit

Permalink
rename feature name based on main unit
Browse files Browse the repository at this point in the history
  • Loading branch information
chatblanc-ciel committed Oct 20, 2023
1 parent c3c6107 commit a5f5c48
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 20 deletions.
1 change: 1 addition & 0 deletions crates/polars-plan/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions crates/polars-plan/src/dsl/function_expr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -878,7 +878,7 @@ impl From<StringFunction> for SpecialEq<Arc<dyn SeriesUdf>> {
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)
Expand Down Expand Up @@ -924,7 +924,7 @@ impl From<StringFunction> for SpecialEq<Arc<dyn SeriesUdf>> {
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),
Expand Down
26 changes: 13 additions & 13 deletions crates/polars-plan/src/dsl/function_expr/strings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -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,
Expand Down Expand Up @@ -57,7 +57,7 @@ pub enum StringFunction {
dtype: Option<DataType>,
infer_schema_len: Option<usize>,
},
#[cfg(feature = "regex")]
#[cfg(feature = "lazy_regex")]
Replace {
// negative is replace all
// how many matches to replace
Expand Down Expand Up @@ -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),
Expand All @@ -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()),
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -244,7 +244,7 @@ pub(super) fn len_bytes(s: &Series) -> PolarsResult<Series> {
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<Series> {
let ca = s[0].utf8()?;
let pat = s[1].utf8()?;
Expand Down Expand Up @@ -569,7 +569,7 @@ impl From<StringFunction> 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"),
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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<Series> {
let column = &s[0];
let pat = &s[1];
Expand Down
10 changes: 5 additions & 5 deletions crates/polars-plan/src/dsl/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -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(
Expand All @@ -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(
Expand All @@ -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(
Expand Down

0 comments on commit a5f5c48

Please sign in to comment.