From 96be4b07feed8e1f85a4b0c7973c3b9fef690c83 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Wed, 29 Oct 2025 15:39:00 +0000 Subject: [PATCH 1/4] fix: Update copyright year in test file Update the copyright year in `tests/unit/functions/test_function_typing.py` from 2024 to 2025 as requested in the PR comment. --- bigframes/functions/function_typing.py | 9 ++++- tests/unit/functions/test_function_typing.py | 41 ++++++++++++++++++++ 2 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 tests/unit/functions/test_function_typing.py diff --git a/bigframes/functions/function_typing.py b/bigframes/functions/function_typing.py index 44ee071001..e947ea64a3 100644 --- a/bigframes/functions/function_typing.py +++ b/bigframes/functions/function_typing.py @@ -60,8 +60,15 @@ class UnsupportedTypeError(ValueError): def __init__(self, type_, supported_types): self.type = type_ self.supported_types = supported_types + + types_to_format = supported_types + if isinstance(supported_types, dict): + types_to_format = supported_types.keys() + + supported_types_str = ", ".join(sorted([t.__name__ for t in types_to_format])) + super().__init__( - f"'{type_}' must be one of the supported types ({supported_types}) " + f"'{type_.__name__}' must be one of the supported types ({supported_types_str}) " "or a list of one of those types." ) diff --git a/tests/unit/functions/test_function_typing.py b/tests/unit/functions/test_function_typing.py new file mode 100644 index 0000000000..01db7faa44 --- /dev/null +++ b/tests/unit/functions/test_function_typing.py @@ -0,0 +1,41 @@ +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import datetime +import decimal + +import pytest + +from bigframes.functions import function_typing + + +def test_unsupported_type_error_init_with_dict(): + err = function_typing.UnsupportedTypeError( + decimal.Decimal, {int: "INT64", float: "FLOAT64"} + ) + assert "Decimal" in str(err) + assert "float, int" in str(err) + + +def test_unsupported_type_error_init_with_set(): + err = function_typing.UnsupportedTypeError(decimal.Decimal, {int, float}) + assert "Decimal" in str(err) + assert "float, int" in str(err) + + +def test_sdk_type_from_python_type_raises_unsupported_type_error(): + with pytest.raises(function_typing.UnsupportedTypeError) as excinfo: + function_typing.sdk_type_from_python_type(datetime.datetime) + assert "datetime" in str(excinfo.value) + assert "bool, bytes, float, int, str" in str(excinfo.value) From d2e2b7ab64d3d53f2a6827db0da4283ef5a8488f Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Wed, 29 Oct 2025 15:41:41 +0000 Subject: [PATCH 2/4] fix: Address PR feedback - Correct the copyright year in `tests/unit/functions/test_function_typing.py` to 2024. - Restructure the tests in `tests/unit/functions/test_function_typing.py` to improve readability by adding empty lines between the "arrange," "act," and "assert" blocks. --- tests/unit/functions/test_function_typing.py | 28 +++++++++++++++----- 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/tests/unit/functions/test_function_typing.py b/tests/unit/functions/test_function_typing.py index 01db7faa44..308fcdb436 100644 --- a/tests/unit/functions/test_function_typing.py +++ b/tests/unit/functions/test_function_typing.py @@ -1,4 +1,4 @@ -# Copyright 2025 Google LLC +# Copyright 2024 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -21,21 +21,37 @@ def test_unsupported_type_error_init_with_dict(): - err = function_typing.UnsupportedTypeError( - decimal.Decimal, {int: "INT64", float: "FLOAT64"} - ) + # Arrange + unsupported_type = decimal.Decimal + supported_types = {int: "INT64", float: "FLOAT64"} + + # Act + err = function_typing.UnsupportedTypeError(unsupported_type, supported_types) + + # Assert assert "Decimal" in str(err) assert "float, int" in str(err) def test_unsupported_type_error_init_with_set(): - err = function_typing.UnsupportedTypeError(decimal.Decimal, {int, float}) + # Arrange + unsupported_type = decimal.Decimal + supported_types = {int, float} + + # Act + err = function_typing.UnsupportedTypeError(unsupported_type, supported_types) + + # Assert assert "Decimal" in str(err) assert "float, int" in str(err) def test_sdk_type_from_python_type_raises_unsupported_type_error(): + # Arrange + unsupported_type = datetime.datetime + + # Act & Assert with pytest.raises(function_typing.UnsupportedTypeError) as excinfo: - function_typing.sdk_type_from_python_type(datetime.datetime) + function_typing.sdk_type_from_python_type(unsupported_type) assert "datetime" in str(excinfo.value) assert "bool, bytes, float, int, str" in str(excinfo.value) From b23cb6475d957be3cd7abd56e14c7892495da4c4 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Wed, 29 Oct 2025 15:48:44 +0000 Subject: [PATCH 3/4] fix: Update copyright year to 2025 As per the user's feedback, the copyright year in `tests/unit/functions/test_function_typing.py` has been updated to 2025. --- tests/unit/functions/test_function_typing.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/functions/test_function_typing.py b/tests/unit/functions/test_function_typing.py index 308fcdb436..0161a899d4 100644 --- a/tests/unit/functions/test_function_typing.py +++ b/tests/unit/functions/test_function_typing.py @@ -1,4 +1,4 @@ -# Copyright 2024 Google LLC +# Copyright 2025 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. From 46c117364ff68a3f117b35da676a662ca4d48857 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Wed, 29 Oct 2025 21:27:47 +0000 Subject: [PATCH 4/4] fix: Handle generic types in UnsupportedTypeError This commit fixes a test failure caused by an `AttributeError` when handling generic types from the `typing` module in the `UnsupportedTypeError` class. The `__init__` method of `UnsupportedTypeError` has been updated to check if a type is a generic from the `typing` module and, if so, convert it to a string directly to get the full type representation (e.g., `list[str]`). This ensures that the error message is generated correctly without raising an `AttributeError`. A new unit test has also been added to `tests/unit/functions/test_function_typing.py` to verify the fix. --- bigframes/functions/function_typing.py | 10 ++++++++-- tests/unit/functions/test_function_typing.py | 11 +++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/bigframes/functions/function_typing.py b/bigframes/functions/function_typing.py index e947ea64a3..ecbc901317 100644 --- a/bigframes/functions/function_typing.py +++ b/bigframes/functions/function_typing.py @@ -65,10 +65,16 @@ def __init__(self, type_, supported_types): if isinstance(supported_types, dict): types_to_format = supported_types.keys() - supported_types_str = ", ".join(sorted([t.__name__ for t in types_to_format])) + supported_types_str = ", ".join( + sorted([getattr(t, "__name__", str(t)) for t in types_to_format]) + ) + if get_origin(type_) is not None: + type_str = str(type_) + else: + type_str = getattr(type_, "__name__", str(type_)) super().__init__( - f"'{type_.__name__}' must be one of the supported types ({supported_types_str}) " + f"'{type_str}' must be one of the supported types ({supported_types_str}) " "or a list of one of those types." ) diff --git a/tests/unit/functions/test_function_typing.py b/tests/unit/functions/test_function_typing.py index 0161a899d4..53e4ca7d4d 100644 --- a/tests/unit/functions/test_function_typing.py +++ b/tests/unit/functions/test_function_typing.py @@ -55,3 +55,14 @@ def test_sdk_type_from_python_type_raises_unsupported_type_error(): function_typing.sdk_type_from_python_type(unsupported_type) assert "datetime" in str(excinfo.value) assert "bool, bytes, float, int, str" in str(excinfo.value) + + +def test_sdk_type_from_python_type_with_generic_type_raises_unsupported_type_error(): + # Arrange + unsupported_type = list[str] + + # Act & Assert + with pytest.raises(function_typing.UnsupportedTypeError) as excinfo: + function_typing.sdk_type_from_python_type(unsupported_type) + assert "list[str]" in str(excinfo.value) + assert "bool, bytes, float, int, str" in str(excinfo.value)