ibis-project / ibis

the portable Python dataframe library
https://ibis-project.org
Apache License 2.0
5.28k stars 595 forks source link

feat: Add the ability to pass regex flags #9274

Open SamEdwardes opened 5 months ago

SamEdwardes commented 5 months ago

Is your feature request related to a problem?

Depending on the backend, regex search my be handled differently. I would like the ability to be able to pass regex flags so that I have complete control over how the regex search is performed.

What is the motivation behind your request?

No response

Describe the solution you'd like

Here is an example of what the API could look like:

con = ibis.postgres.connect()
x = con.table("x")
ibis.to_sql(
    x
    .filter([x.body.re_search('kubernetes', flags='i')])
    .limit(10)

)

In this example, adding the i flag, which would make the search case insensitive.

What version of ibis are you running?

ibis-framework[postgres]==9.0.0

What backend(s) are you using, if any?

postgres, but I think it would be helpful to have this feature for all backends that support regex search.

Code of Conduct

cpcloud commented 5 months ago

One option if you must have the flags before we investigate here is to define a builtin UDF.

Something like this:

@ibis.udf.scalar.builtin(name="regexp_search")
def re_search(s, pattern, flags):
    ...
SamEdwardes commented 5 months ago

Thanks for the suggestion @cpcloud! I do implement this I will report back here.