Skip to content

Commit

Permalink
Simplify contains check that opts-in to contains_literal fast-path (
Browse files Browse the repository at this point in the history
#3736)

* improve check that can automatically opt-in to the "contains_literal" fast-path

* simplify fast-path check, unwinding regex-syntax dependency
  • Loading branch information
alexander-beedie committed Jun 19, 2022
1 parent efae6b2 commit 4c6f9cd
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 5 deletions.
5 changes: 1 addition & 4 deletions polars/polars-ops/src/chunked_array/strings/namespace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,7 @@ pub trait Utf8NameSpaceImpl: AsUtf8 {

/// Check if strings contain a regex pattern; select literal fast-path if no special chars
fn contains(&self, pat: &str) -> Result<BooleanChunked> {
if pat
.chars()
.all(|c| c.is_alphanumeric() || c.is_whitespace() || (c == '_'))
{
if pat.chars().all(|c| !c.is_ascii_punctuation()) {
self.contains_literal(pat)
} else {
let ca = self.as_utf8();
Expand Down
2 changes: 1 addition & 1 deletion polars/tests/it/lazy/expressions/arity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ fn includes_null_predicate_3038() -> Result<()> {
move |s| {
s.utf8()?
.to_lowercase()
.contains("non-existent")
.contains_literal("non-existent")
.map(Into::into)
},
GetOutput::from_type(DataType::Boolean),
Expand Down

0 comments on commit 4c6f9cd

Please sign in to comment.