Skip to content

Commit d05217b

Browse files
committed
fix: make start truly optional in regexp_count
1 parent 8d7d9f2 commit d05217b

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

python/datafusion/functions.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -817,7 +817,7 @@ def regexp_replace(
817817

818818

819819
def regexp_count(
820-
string: Expr, pattern: Expr, start: Expr, flags: Expr | None = None
820+
string: Expr, pattern: Expr, start: Expr | None = None, flags: Expr | None = None
821821
) -> Expr:
822822
"""Returns the number of matches in a string.
823823
@@ -826,7 +826,7 @@ def regexp_count(
826826
"""
827827
if flags is not None:
828828
flags = flags.expr
829-
start = start.expr if start is not None else Expr.expr
829+
start = (start if start is not None else Expr.literal(1)).expr
830830
return Expr(f.regexp_count(string.expr, pattern.expr, start, flags))
831831

832832

python/tests/test_functions.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -772,6 +772,10 @@ def test_array_function_obj_tests(stmt, py_expr):
772772
f.regexp_count(column("a"), literal("(ell|orl)"), literal(1)),
773773
pa.array([1, 1, 0], type=pa.int64()),
774774
),
775+
(
776+
f.regexp_count(column("a"), literal("(ell|orl)")),
777+
pa.array([1, 1, 0], type=pa.int64()),
778+
),
775779
(
776780
f.regexp_instr(column("a"), literal("(ell|orl)")),
777781
pa.array([2, 2, 0], type=pa.int64()),

0 commit comments

Comments
 (0)