Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion bigframes/dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -3674,7 +3674,11 @@ def apply(self, func, *, axis=0, args: typing.Tuple = (), **kwargs):
return result_series

# Per-column apply
results = {name: func(col, *args, **kwargs) for name, col in self.items()}
if hasattr(func, "bigframes_remote_function"):
results = {name: col.apply(func) for name, col in self.items()}
else:
results = {name: func(col, *args, **kwargs) for name, col in self.items()}

if all(
[
isinstance(val, bigframes.series.Series) or utils.is_list_like(val)
Expand Down
17 changes: 17 additions & 0 deletions tests/system/small/test_dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -1161,6 +1161,23 @@ def test_apply_series_scalar_callable(
pandas.testing.assert_series_equal(bf_result, pd_result)


def test_apply_from_read_gbq_function(dataset_id_permanent):
@bpd.remote_function()
def tenfold(num: float) -> float:
return num * 10.0

# Read back the deployed BQ remote function via read_gbq_function.
tenfold_ref = bpd.read_gbq_function(function_name=tenfold.bigframes_remote_function)

data = {"a": [1.0, 2.0], "b": [3.0, 4.0], "c": [5.0, 6.0]}
bdf = bpd.DataFrame(data)
# Applying the remote function in different ways should result in the same results.
result = bdf.apply(tenfold).to_pandas()
result_gbq = bdf.apply(tenfold_ref).to_pandas()

pandas.testing.assert_frame_equal(result, result_gbq)


def test_df_pipe(
scalars_df_index,
scalars_pandas_df_index,
Expand Down
Loading