Skip to content

feat: allow input_types, output_type, and dataset to be used positionally in remote_function #1560

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

Merged
merged 1 commit into from
Mar 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

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/pandas/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,14 @@


def remote_function(
*,
# Make sure that the input/output types, and dataset can be used
# positionally. This avoids the worst of the breaking change from 1.x to
# 2.x while still preventing possible mixups between consecutive str
# parameters.
input_types: Union[None, type, Sequence[type]] = None,
output_type: Optional[type] = None,
dataset: Optional[str] = None,
*,
bigquery_connection: Optional[str] = None,
reuse: bool = True,
name: Optional[str] = None,
Expand Down
6 changes: 5 additions & 1 deletion bigframes/session/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1202,10 +1202,14 @@ def _check_file_size(self, filepath: str):

def remote_function(
self,
*,
# Make sure that the input/output types, and dataset can be used
# positionally. This avoids the worst of the breaking change from 1.x to
# 2.x while still preventing possible mixups between consecutive str
# parameters.
input_types: Union[None, type, Sequence[type]] = None,
output_type: Optional[type] = None,
dataset: Optional[str] = None,
*,
bigquery_connection: Optional[str] = None,
reuse: bool = True,
name: Optional[str] = None,
Expand Down
76 changes: 48 additions & 28 deletions tests/system/large/functions/test_remote_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,11 @@ def test_remote_function_multiply_with_ibis(
try:

@session.remote_function(
input_types=[int, int],
output_type=int,
dataset=dataset_id,
# Make sure that the input/output types can be used positionally.
# This avoids the worst of the breaking change from 1.x to 2.x.
[int, int],
int,
dataset_id,
bigquery_connection=bq_cf_connection,
reuse=False,
cloud_function_service_account="default",
Expand Down Expand Up @@ -164,9 +166,11 @@ def test_remote_function_stringify_with_ibis(
try:

@session.remote_function(
input_types=[int],
output_type=str,
dataset=dataset_id,
# Make sure that the input/output types can be used positionally.
# This avoids the worst of the breaking change from 1.x to 2.x.
[int],
str,
dataset_id,
bigquery_connection=bq_cf_connection,
reuse=False,
cloud_function_service_account="default",
Expand Down Expand Up @@ -213,9 +217,11 @@ def func(x, y):
return x * abs(y % 4)

remote_func = session.remote_function(
input_types=[str, int],
output_type=str,
dataset=dataset_id,
# Make sure that the input/output types can be used positionally.
# This avoids the worst of the breaking change from 1.x to 2.x.
[str, int],
str,
dataset_id,
bigquery_connection=bq_cf_connection,
reuse=False,
cloud_function_service_account="default",
Expand Down Expand Up @@ -251,9 +257,11 @@ def func(x, y):
return [len(x), abs(y % 4)]

remote_func = session.remote_function(
input_types=[str, int],
output_type=list[int],
dataset=dataset_id,
# Make sure that the input/output types can be used positionally.
# This avoids the worst of the breaking change from 1.x to 2.x.
[str, int],
list[int],
dataset_id,
bigquery_connection=bq_cf_connection,
reuse=False,
cloud_function_service_account="default",
Expand Down Expand Up @@ -286,9 +294,11 @@ def test_remote_function_decorator_with_bigframes_series(
try:

@session.remote_function(
input_types=[int],
output_type=int,
dataset=dataset_id,
# Make sure that the input/output types can be used positionally.
# This avoids the worst of the breaking change from 1.x to 2.x.
[int],
int,
dataset_id,
bigquery_connection=bq_cf_connection,
reuse=False,
cloud_function_service_account="default",
Expand Down Expand Up @@ -333,9 +343,11 @@ def add_one(x):
return x + 1

remote_add_one = session.remote_function(
input_types=[int],
output_type=int,
dataset=dataset_id,
# Make sure that the input/output types can be used positionally.
# This avoids the worst of the breaking change from 1.x to 2.x.
[int],
int,
dataset_id,
bigquery_connection=bq_cf_connection,
reuse=False,
cloud_function_service_account="default",
Expand Down Expand Up @@ -385,8 +397,10 @@ def add_one(x):
return x + 1

remote_add_one = session.remote_function(
input_types=input_types,
output_type=int,
# Make sure that the input/output types can be used positionally.
# This avoids the worst of the breaking change from 1.x to 2.x.
input_types,
int,
reuse=False,
cloud_function_service_account="default",
)(add_one)
Expand Down Expand Up @@ -415,8 +429,10 @@ def test_remote_function_explicit_dataset_not_created(
try:

@session.remote_function(
input_types=[int],
output_type=int,
# Make sure that the input/output types can be used positionally.
# This avoids the worst of the breaking change from 1.x to 2.x.
[int],
int,
dataset=dataset_id_not_created,
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I missed this one, but I think it's good to have some tests with the keyword version of the parameter too.

bigquery_connection=bq_cf_connection,
reuse=False,
Expand Down Expand Up @@ -469,9 +485,11 @@ def sign(num):
return NO_SIGN

remote_sign = session.remote_function(
input_types=[int],
output_type=int,
dataset=dataset_id,
# Make sure that the input/output types can be used positionally.
# This avoids the worst of the breaking change from 1.x to 2.x.
[int],
int,
dataset_id,
bigquery_connection=bq_cf_connection,
reuse=False,
cloud_function_service_account="default",
Expand Down Expand Up @@ -517,9 +535,11 @@ def circumference(radius):
return 2 * mymath.pi * radius

remote_circumference = session.remote_function(
input_types=[float],
output_type=float,
dataset=dataset_id,
# Make sure that the input/output types can be used positionally.
# This avoids the worst of the breaking change from 1.x to 2.x.
[float],
float,
dataset_id,
bigquery_connection=bq_cf_connection,
reuse=False,
cloud_function_service_account="default",
Expand Down