@@ -4716,13 +4716,17 @@ def _prepare_export(
47164716 return array_value , id_overrides
47174717
47184718 def map (self , func , na_action : Optional [str ] = None ) -> DataFrame :
4719- if not isinstance (func , bigframes .functions .Udf ):
4719+ from bigframes ._config import options
4720+
4721+ if not isinstance (func , bigframes .functions .Udf ) and not (
4722+ options .experiments .enable_python_transpiler and callable (func )
4723+ ):
47204724 raise TypeError ("the first argument must be callable" )
47214725
47224726 if na_action not in {None , "ignore" }:
47234727 raise ValueError (f"na_action={ na_action } not supported" )
47244728
4725- expr = ops .func_to_op (func ).as_expr (ex .free_var ("input" ))
4729+ expr = ops .func_to_expr (func ).apply (ex .free_var ("input" ))
47264730 if na_action == "ignore" :
47274731 # True case, predicate, False case
47284732 expr = ops .where_op .as_expr (
@@ -4742,11 +4746,25 @@ def apply(self, func, *, axis=0, args: typing.Tuple = (), **kwargs):
47424746 )
47434747 warnings .warn (msg , category = bfe .FunctionAxisOnePreviewWarning )
47444748
4745- if not isinstance (func , bigframes .functions .Udf ):
4749+ from bigframes ._config import options
4750+
4751+ if not isinstance (func , bigframes .functions .Udf ) and not (
4752+ options .experiments .enable_python_transpiler and callable (func )
4753+ ):
47464754 raise ValueError (
47474755 "For axis=1 a BigFrames BigQuery function must be used."
47484756 )
47494757
4758+ if (
4759+ not isinstance (func , bigframes .functions .Udf )
4760+ and options .experiments .enable_python_transpiler
4761+ and callable (func )
4762+ ):
4763+ result_block = block_ops .apply_to_block_rows (
4764+ func , self ._block , * args , ** kwargs
4765+ )
4766+ return bigframes .series .Series (result_block )
4767+
47504768 if func .udf_def .signature .is_row_processor :
47514769 # Early check whether the dataframe dtypes are currently supported
47524770 # in the bigquery function
@@ -4800,8 +4818,14 @@ def apply(self, func, *, axis=0, args: typing.Tuple = (), **kwargs):
48004818 )
48014819
48024820 # Apply the function
4821+ expr = ops .func_to_expr (func ).expr
4822+ if not (
4823+ isinstance (expr , ex .OpExpression )
4824+ and isinstance (expr .op , ops .NaryOp )
4825+ ):
4826+ raise TypeError (f"Expected OpExpression with NaryOp, got { expr } " )
48034827 result_series = rows_as_json_series ._apply_nary_op (
4804- ops . func_to_op ( func ) ,
4828+ expr . op ,
48054829 list (args ),
48064830 )
48074831
@@ -4861,8 +4885,8 @@ def apply(self, func, *, axis=0, args: typing.Tuple = (), **kwargs):
48614885
48624886 series_list = [self [col ] for col in self .columns ]
48634887 op_list = series_list [1 :] + list (args )
4864- result_series = series_list [0 ]._apply_nary_op (
4865- ops .func_to_op (func ), op_list
4888+ result_series = series_list [0 ]._apply_callable_expr (
4889+ ops .func_to_expr (func ), op_list
48664890 )
48674891 result_series .name = None
48684892
0 commit comments