-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat: Experimental transpilation of unannotated python callables #17419
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
Changes from all commits
2dd2003
b11f211
cbe405b
0f42849
2488374
8f42da1
910027e
a61ae8b
c117c50
d2b980c
7d52cd4
91f65dc
02a970a
8980fde
aa6d9ab
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4692,13 +4692,17 @@ def _prepare_export( | |
| return array_value, id_overrides | ||
|
|
||
| def map(self, func, na_action: Optional[str] = None) -> DataFrame: | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd love to see an example in the docstrings, especially if this is compatible with the polars engine and thus would make for a relatively speedy flakeless doctest.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added doctests |
||
| if not isinstance(func, bigframes.functions.Udf): | ||
| from bigframes._config import options | ||
|
|
||
| if not isinstance(func, bigframes.functions.Udf) and not ( | ||
| options.experiments.enable_python_transpiler and callable(func) | ||
| ): | ||
| raise TypeError("the first argument must be callable") | ||
|
|
||
| if na_action not in {None, "ignore"}: | ||
| raise ValueError(f"na_action={na_action} not supported") | ||
|
|
||
| expr = ops.func_to_op(func).as_expr(ex.free_var("input")) | ||
| expr = ops.func_to_expr(func).apply(ex.free_var("input")) | ||
| if na_action == "ignore": | ||
| # True case, predicate, False case | ||
| expr = ops.where_op.as_expr( | ||
|
|
@@ -4718,11 +4722,25 @@ def apply(self, func, *, axis=0, args: typing.Tuple = (), **kwargs): | |
| ) | ||
| warnings.warn(msg, category=bfe.FunctionAxisOnePreviewWarning) | ||
|
|
||
| if not isinstance(func, bigframes.functions.Udf): | ||
| from bigframes._config import options | ||
|
|
||
| if not isinstance(func, bigframes.functions.Udf) and not ( | ||
| options.experiments.enable_python_transpiler and callable(func) | ||
| ): | ||
| raise ValueError( | ||
| "For axis=1 a BigFrames BigQuery function must be used." | ||
| ) | ||
|
|
||
| if ( | ||
| not isinstance(func, bigframes.functions.Udf) | ||
| and options.experiments.enable_python_transpiler | ||
| and callable(func) | ||
| ): | ||
| result_block = block_ops.apply_to_block_rows( | ||
| func, self._block, *args, **kwargs | ||
| ) | ||
| return bigframes.series.Series(result_block) | ||
|
|
||
| if func.udf_def.signature.is_row_processor: | ||
| # Early check whether the dataframe dtypes are currently supported | ||
| # in the bigquery function | ||
|
|
@@ -4776,8 +4794,14 @@ def apply(self, func, *, axis=0, args: typing.Tuple = (), **kwargs): | |
| ) | ||
|
|
||
| # Apply the function | ||
| expr = ops.func_to_expr(func).expr | ||
| if not ( | ||
| isinstance(expr, ex.OpExpression) | ||
| and isinstance(expr.op, ops.NaryOp) | ||
| ): | ||
| raise TypeError(f"Expected OpExpression with NaryOp, got {expr}") | ||
| result_series = rows_as_json_series._apply_nary_op( | ||
| ops.func_to_op(func), | ||
| expr.op, | ||
| list(args), | ||
| ) | ||
|
|
||
|
|
@@ -4837,8 +4861,8 @@ def apply(self, func, *, axis=0, args: typing.Tuple = (), **kwargs): | |
|
|
||
| series_list = [self[col] for col in self.columns] | ||
| op_list = series_list[1:] + list(args) | ||
| result_series = series_list[0]._apply_nary_op( | ||
| ops.func_to_op(func), op_list | ||
| result_series = series_list[0]._apply_callable_expr( | ||
| ops.func_to_expr(func), op_list | ||
| ) | ||
| result_series.name = None | ||
|
|
||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a bug number for this one?