polars icon indicating copy to clipboard operation
polars copied to clipboard

Expose regex::escape in Polars Python API

Open orlp opened this issue 1 year ago • 6 comments

Polars uses the Rust regex crate as its regex engine. When building patterns it is sometimes desired to put an untrusted/unknown string as a literal in the regex. To do this correctly you need to escape that string. However, re.escape in Python is not the correct function for this, it should match the engine we use, so we need to expose regex::escape in our interface.

I would suggest exposing it as pl.escape_regex which directly works on Python strings, and pl.Expr.str.escape_regex which applies it to a column of strings.

orlp avatar Oct 12 '24 08:10 orlp

@cmdlineluser Oops, I forgot to search for duplicates 😓

orlp avatar Oct 12 '24 09:10 orlp

Good plan; can then retire this utility function: https://github.com/pola-rs/polars/blob/48f6e9dc7c62f60ee9cb2ef9313917b63c96b1f7/py-polars/polars/_utils/various.py#L626

alexander-beedie avatar Oct 12 '24 18:10 alexander-beedie

@barak1412 would you be interested in this one? You are getting familiar with the Expressions setup.

ritchie46 avatar Oct 14 '24 06:10 ritchie46

@ritchie46 Sure! I am little sick now, but I will get to it in couple of days.

barak1412 avatar Oct 14 '24 07:10 barak1412

Ai, take care. :raised_hands:

ritchie46 avatar Oct 14 '24 07:10 ritchie46

@ritchie46 Thanks!

@orlp May you assign me please?

barak1412 avatar Oct 15 '24 05:10 barak1412