Skip to content

Commit

Permalink
feat(polars): add StringFind operation (#10624)
Browse files Browse the repository at this point in the history
  • Loading branch information
IndexSeek authored Dec 28, 2024
1 parent 28bafd1 commit 5e8855d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
9 changes: 9 additions & 0 deletions ibis/backends/polars/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -1555,3 +1555,12 @@ def visit_ArrayIntersect(op, **kw):
left = translate(op.left, **kw)
right = translate(op.right, **kw)
return left.list.set_intersection(right)


@translate.register(ops.StringFind)
def visit_StringFind(op, **kw):
arg = translate(op.arg, **kw)
start = translate(op.start, **kw) if op.start is not None else 0
end = translate(op.end, **kw) if op.end is not None else None
expr = arg.str.slice(start, end).str.find(_literal_value(op.substr), literal=True)
return pl.when(expr.is_null()).then(-1).otherwise(expr + start)
5 changes: 0 additions & 5 deletions ibis/backends/tests/test_string.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,15 +406,11 @@ def uses_java_re(t):
lambda t: t.string_col.find("a"),
lambda t: t.string_col.str.find("a"),
id="find",
marks=pytest.mark.notimpl(["polars"], raises=com.OperationNotDefinedError),
),
param(
lambda t: t.date_string_col.find("13", 3),
lambda t: t.date_string_col.str.find("13", 3),
id="find_start",
marks=[
pytest.mark.notimpl(["polars"], raises=com.OperationNotDefinedError),
],
),
param(
lambda t: t.string_col.lpad(10, "a"),
Expand Down Expand Up @@ -1084,7 +1080,6 @@ def string_temp_table(backend, con):
lambda t: t.string_col.find("123"),
lambda t: t.str.find("123"),
id="find",
marks=pytest.mark.notimpl("polars", raises=com.OperationNotDefinedError),
),
param(
lambda t: t.string_col.rpad(4, "-"),
Expand Down

0 comments on commit 5e8855d

Please sign in to comment.