Copilot commented on code in PR #1484:
URL: 
https://github.com/apache/datafusion-python/pull/1484#discussion_r3059185223


##########
python/datafusion/functions.py:
##########
@@ -1628,56 +1678,65 @@ def regexp_instr(
 
         >>> result = df.select(
         ...     dfn.functions.regexp_instr(
-        ...         dfn.col("a"), dfn.lit("(abc)"),
-        ...         sub_expr=dfn.lit(1),
+        ...         dfn.col("a"), "(abc)", sub_expr=1,
         ...     ).alias("pos")
         ... )
         >>> result.collect_column("pos")[0].as_py()
         1
     """
-    start = start.expr if start is not None else None
-    n = n.expr if n is not None else None
-    flags = flags.expr if flags is not None else None
-    sub_expr = sub_expr.expr if sub_expr is not None else None
+    if not isinstance(regex, Expr):
+        regex = Expr.literal(regex)
+
+    def _to_raw(val: Any) -> Any:
+        if val is None:
+            return None
+        if not isinstance(val, Expr):
+            val = Expr.literal(val)
+        return val.expr
 
     return Expr(
         f.regexp_instr(
             values.expr,
             regex.expr,
-            start,
-            n,
-            flags,
-            sub_expr,
+            _to_raw(start),
+            _to_raw(n),
+            _to_raw(flags),
+            _to_raw(sub_expr),
         )
     )

Review Comment:
   `regexp_instr` introduces a nested `_to_raw` helper, which is inconsistent 
with the inline coercion approach used throughout the rest of this file (and 
conflicts with the newly-added skill guidance that explicitly says not to 
introduce helper functions for coercion). Recommend expanding this to explicit 
inline conversions per-argument (similar to `regexp_count` / `string_to_array`) 
so the coercion is uniform and easier to scan/review. Also, the use of `Any` 
here requires `Any` to be in scope for annotation evaluation; avoiding `Any` 
(or ensuring it’s imported / annotations are deferred) prevents potential 
runtime issues.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to