Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(polars): add StringFind operation #10624

Merged
merged 1 commit into from
Dec 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading