Skip to content

Commit 770918e

Browse files
authored
fix: Enhance type error messages for bigframes functions (#1958)
1 parent 2f524e6 commit 770918e

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

bigframes/functions/function_typing.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ def __init__(self, type_, supported_types):
6161
self.type = type_
6262
self.supported_types = supported_types
6363
super().__init__(
64-
f"'{type_}' is not one of the supported types {supported_types}"
64+
f"'{type_}' must be one of the supported types ({supported_types}) "
65+
"or a list of one of those types."
6566
)
6667

6768

tests/system/small/functions/test_remote_function.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import inspect
1616
import re
1717
import textwrap
18+
from typing import Sequence
1819

1920
import bigframes_vendored.constants as constants
2021
import google.api_core.exceptions
@@ -1642,3 +1643,29 @@ def processor(x: int, y: int, z: float, w: str) -> str:
16421643
df = scalars_df_index[["int64_col", "int64_too", "float64_col", "string_col"]]
16431644
df1 = df.assign(combined=df.apply(processor, axis=1))
16441645
repr(df1)
1646+
1647+
1648+
@pytest.mark.flaky(retries=2, delay=120)
1649+
def test_remote_function_unsupported_type(
1650+
session,
1651+
dataset_id_permanent,
1652+
bq_cf_connection,
1653+
):
1654+
# Remote functions do not support tuple return types.
1655+
def func_tuple(x):
1656+
return (x, x, x)
1657+
1658+
with pytest.raises(
1659+
ValueError,
1660+
match=r"'typing\.Sequence\[int\]' must be one of the supported types",
1661+
):
1662+
bff.remote_function(
1663+
input_types=int,
1664+
output_type=Sequence[int],
1665+
session=session,
1666+
dataset=dataset_id_permanent,
1667+
bigquery_connection=bq_cf_connection,
1668+
reuse=True,
1669+
name=get_function_name(func_tuple),
1670+
cloud_function_service_account="default",
1671+
)(func_tuple)

0 commit comments

Comments
 (0)