@@ -843,22 +843,31 @@ def test_remote_function_with_external_package_dependencies(
843
843
):
844
844
try :
845
845
846
- def pd_np_foo (x ):
846
+ # The return type hint in this function's signature has conflict. The
847
+ # `output_type` argument from remote_function decorator takes precedence
848
+ # and will be used instead.
849
+ def pd_np_foo (x ) -> None :
847
850
import numpy as mynp
848
851
import pandas as mypd
849
852
850
853
return mypd .Series ([x , mynp .sqrt (mynp .abs (x ))]).sum ()
851
854
852
- # Create the remote function with the name provided explicitly
853
- pd_np_foo_remote = session .remote_function (
854
- input_types = [int ],
855
- output_type = float ,
856
- dataset = dataset_id ,
857
- bigquery_connection = bq_cf_connection ,
858
- reuse = False ,
859
- packages = ["numpy" , "pandas >= 2.0.0" ],
860
- cloud_function_service_account = "default" ,
861
- )(pd_np_foo )
855
+ with warnings .catch_warnings (record = True ) as record :
856
+ # Create the remote function with the name provided explicitly
857
+ pd_np_foo_remote = session .remote_function (
858
+ input_types = [int ],
859
+ output_type = float ,
860
+ dataset = dataset_id ,
861
+ bigquery_connection = bq_cf_connection ,
862
+ reuse = False ,
863
+ packages = ["numpy" , "pandas >= 2.0.0" ],
864
+ cloud_function_service_account = "default" ,
865
+ )(pd_np_foo )
866
+
867
+ input_type_warning = "Conflicting input types detected"
868
+ assert not any (input_type_warning in str (warning .message ) for warning in record )
869
+ return_type_warning = "Conflicting return type detected"
870
+ assert any (return_type_warning in str (warning .message ) for warning in record )
862
871
863
872
# The behavior of the created remote function should be as expected
864
873
scalars_df , scalars_pandas_df = scalars_dfs
@@ -1999,10 +2008,25 @@ def test_remote_function_unnamed_removed_w_session_cleanup():
1999
2008
# create a clean session
2000
2009
session = bigframes .connect ()
2001
2010
2002
- # create an unnamed remote function in the session
2003
- @session .remote_function (reuse = False , cloud_function_service_account = "default" )
2004
- def foo (x : int ) -> int :
2005
- return x + 1
2011
+ with warnings .catch_warnings (record = True ) as record :
2012
+ # create an unnamed remote function in the session.
2013
+ # The type hints in this function's signature are redundant. The
2014
+ # `input_types` and `output_type` arguments from remote_function
2015
+ # decorator take precedence and will be used instead.
2016
+ @session .remote_function (
2017
+ input_types = [int ],
2018
+ output_type = int ,
2019
+ reuse = False ,
2020
+ cloud_function_service_account = "default" ,
2021
+ )
2022
+ def foo (x : int ) -> int :
2023
+ return x + 1
2024
+
2025
+ # No following warning with only redundant type hints (no conflict).
2026
+ input_type_warning = "Conflicting input types detected"
2027
+ assert not any (input_type_warning in str (warning .message ) for warning in record )
2028
+ return_type_warning = "Conflicting return type detected"
2029
+ assert not any (return_type_warning in str (warning .message ) for warning in record )
2006
2030
2007
2031
# ensure that remote function artifacts are created
2008
2032
assert foo .bigframes_remote_function is not None
0 commit comments