@@ -1904,9 +1904,22 @@ def _groupby_values(
19041904 )
19051905
19061906 def apply (
1907- self , func , by_row : typing .Union [typing .Literal ["compat" ], bool ] = "compat"
1907+ self ,
1908+ func ,
1909+ by_row : typing .Union [typing .Literal ["compat" ], bool ] = "compat" ,
1910+ * ,
1911+ args : typing .Tuple = (),
19081912 ) -> Series :
1909- # TODO(shobs, b/274645634): Support convert_dtype, args, **kwargs
1913+ # Note: This signature differs from pandas.Series.apply. Specifically,
1914+ # `args` is keyword-only and `by_row` is a custom parameter here. Full
1915+ # alignment would involve breaking changes. However, given that by_row
1916+ # is not frequently used, we defer any such changes until there is a
1917+ # clear need based on user feedback.
1918+ #
1919+ # See pandas docs for reference:
1920+ # https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.Series.apply.html
1921+
1922+ # TODO(shobs, b/274645634): Support convert_dtype, **kwargs
19101923 # is actually a ternary op
19111924
19121925 if by_row not in ["compat" , False ]:
@@ -1950,10 +1963,19 @@ def apply(
19501963 raise
19511964
19521965 # We are working with bigquery function at this point
1953- result_series = self ._apply_unary_op (
1954- ops .RemoteFunctionOp (function_def = func .udf_def , apply_on_null = True )
1955- )
1966+ if args :
1967+ result_series = self ._apply_nary_op (
1968+ ops .NaryRemoteFunctionOp (function_def = func .udf_def ), args
1969+ )
1970+ # TODO(jialuo): Investigate why `_apply_nary_op` drops the series
1971+ # `name`. Manually reassigning it here as a temporary fix.
1972+ result_series .name = self .name
1973+ else :
1974+ result_series = self ._apply_unary_op (
1975+ ops .RemoteFunctionOp (function_def = func .udf_def , apply_on_null = True )
1976+ )
19561977 result_series = func ._post_process_series (result_series )
1978+
19571979 return result_series
19581980
19591981 def combine (
0 commit comments