Skip to content

feat: Support other Expr/Series in str.contains for polars and SQL-like backends#3473

Merged
FBruzzesi merged 7 commits intomainfrom
feat/support-expr-in-str-contains
Mar 30, 2026
Merged

feat: Support other Expr/Series in str.contains for polars and SQL-like backends#3473
FBruzzesi merged 7 commits intomainfrom
feat/support-expr-in-str-contains

Conversation

@FBruzzesi
Copy link
Copy Markdown
Member

Description

For polars and SQL-like backends it's straightforward to support expressions and series in str.contains.
For pandas, pyarrow and dask a better error is not raised

What type of PR is this? (check all applicable)

  • 💾 Refactor
  • ✨ Feature
  • 🐛 Bug Fix
  • 🔧 Optimization
  • 📝 Documentation
  • ✅ Test
  • 🐳 Other

Related issues

Checklist

  • Code follows style guide (ruff)
  • Tests added
  • Documented the changes

@FBruzzesi FBruzzesi added the enhancement New feature or request label Feb 9, 2026
Copy link
Copy Markdown
Member

@MarcoGorelli MarcoGorelli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks @FBruzzesi !

on board with the feature, implementation-wise is it possible to follow str.replace more closely for what we do there for value (which can be an expression)?

if literal:
return self._function("contains", expr, self._lit(pattern))
return self._function("regexp_matches", expr, self._lit(pattern))
def contains(self, pattern: str | SQLExprT, *, literal: bool) -> SQLExprT:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'm a little skeptical of the signature here, as for str.replace we have

def replace_all(self, value: SQLExprT, pattern: str, *, literal: bool) -> SQLExprT:

@FBruzzesi FBruzzesi requested a review from MarcoGorelli March 29, 2026 20:23
Copy link
Copy Markdown
Member

@MarcoGorelli MarcoGorelli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks @FBruzzesi !

@FBruzzesi FBruzzesi merged commit 86cd0ab into main Mar 30, 2026
38 of 39 checks passed
@FBruzzesi FBruzzesi deleted the feat/support-expr-in-str-contains branch March 30, 2026 09:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: str.contains fails if passed Expr as match

2 participants