Skip to content

Commit fe4fbb4

Browse files
refactor: rename the bigframes function files (#1312)
* refactor: rename the bigframes function files * fix the import * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --------- Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
1 parent bd3f584 commit fe4fbb4

File tree

13 files changed

+60
-69
lines changed

13 files changed

+60
-69
lines changed

bigframes/dataframe.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3996,7 +3996,7 @@ def apply(self, func, *, axis=0, args: typing.Tuple = (), **kwargs):
39963996
# Early check whether the dataframe dtypes are currently supported
39973997
# in the remote function
39983998
# NOTE: Keep in sync with the value converters used in the gcf code
3999-
# generated in remote_function_template.py
3999+
# generated in function_template.py
40004000
remote_function_supported_dtypes = (
40014001
bigframes.dtypes.INT_DTYPE,
40024002
bigframes.dtypes.FLOAT_DTYPE,

bigframes/functions/_remote_function_client.py renamed to bigframes/functions/_function_client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
from bigframes_vendored import constants
3030
import requests
3131

32-
import bigframes.functions.remote_function_template
32+
import bigframes.functions.function_template as bff_template
3333

3434
if TYPE_CHECKING:
3535
from bigframes.session import Session
@@ -215,7 +215,7 @@ def generate_cloud_function_code(
215215
f.write("\n".join(package_requirements))
216216

217217
# main.py
218-
entry_point = bigframes.functions.remote_function_template.generate_cloud_function_main_code(
218+
entry_point = bff_template.generate_cloud_function_main_code(
219219
def_,
220220
directory,
221221
input_types=input_types,

bigframes/functions/_remote_function_session.py renamed to bigframes/functions/_function_session.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,7 @@
5252

5353
import pandas
5454

55-
from . import _remote_function_client as rf_client
56-
from . import _utils
55+
from . import _function_client, _utils
5756

5857

5958
class RemoteFunctionSession:
@@ -468,7 +467,7 @@ def wrapper(func):
468467
signature, input_types, output_type # type: ignore
469468
)
470469

471-
remote_function_client = rf_client.RemoteFunctionClient(
470+
remote_function_client = _function_client.RemoteFunctionClient(
472471
dataset_ref.project,
473472
cloud_function_region,
474473
cloud_functions_client,

bigframes/functions/remote_function.py renamed to bigframes/functions/function.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@
3535
import bigframes.core.compile.ibis_types
3636
import bigframes.dtypes
3737
import bigframes.exceptions as bfe
38-
import bigframes.functions.remote_function_template
38+
import bigframes.functions.function_template
3939

40-
from . import _remote_function_session as rf_session
40+
from . import _function_session as bff_session
4141
from . import _utils
4242

4343
logger = logging.getLogger(__name__)
@@ -120,11 +120,11 @@ def get_routine_reference(
120120

121121

122122
def remote_function(*args, **kwargs):
123-
remote_function_session = rf_session.RemoteFunctionSession()
123+
remote_function_session = bff_session.RemoteFunctionSession()
124124
return remote_function_session.remote_function(*args, **kwargs)
125125

126126

127-
remote_function.__doc__ = rf_session.RemoteFunctionSession.remote_function.__doc__
127+
remote_function.__doc__ = bff_session.RemoteFunctionSession.remote_function.__doc__
128128

129129

130130
def read_gbq_function(

bigframes/pandas/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
import bigframes.core.tools
3535
import bigframes.dataframe
3636
import bigframes.enums
37-
import bigframes.functions._utils as functions_utils
37+
import bigframes.functions._utils as bff_utils
3838
from bigframes.pandas.io.api import (
3939
from_glob_path,
4040
read_csv,
@@ -222,7 +222,7 @@ def clean_up_by_session_id(
222222
session.bqclient, dataset, session_id
223223
)
224224

225-
functions_utils._clean_up_by_session_id(
225+
bff_utils._clean_up_by_session_id(
226226
session.bqclient, session.cloudfunctionsclient, dataset, session_id
227227
)
228228

bigframes/session/__init__.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@
6767
import bigframes.dtypes
6868
import bigframes.exceptions
6969
import bigframes.exceptions as bfe
70-
import bigframes.functions._remote_function_session as bigframes_rf_session
71-
import bigframes.functions.remote_function as bigframes_rf
70+
import bigframes.functions._function_session as bff_session
71+
import bigframes.functions.function as bff
7272
import bigframes.session._io.bigquery as bf_io_bigquery
7373
import bigframes.session.clients
7474
import bigframes.session.executor
@@ -245,7 +245,7 @@ def __init__(
245245
)
246246

247247
self._metrics = bigframes.session.metrics.ExecutionMetrics()
248-
self._remote_function_session = bigframes_rf_session.RemoteFunctionSession()
248+
self._function_session = bff_session.RemoteFunctionSession()
249249
self._temp_storage_manager = (
250250
bigframes.session.temp_storage.TemporaryGbqStorageManager(
251251
self._clients_provider.bqclient,
@@ -377,9 +377,9 @@ def close(self):
377377
if temp_storage_manager:
378378
self._temp_storage_manager.clean_up_tables()
379379

380-
remote_function_session = getattr(self, "_remote_function_session", None)
380+
remote_function_session = getattr(self, "_function_session", None)
381381
if remote_function_session:
382-
self._remote_function_session.clean_up(
382+
self._function_session.clean_up(
383383
self.bqclient, self.cloudfunctionsclient, self.session_id
384384
)
385385

@@ -1380,7 +1380,7 @@ def remote_function(
13801380
13811381
`bigframes_remote_function` - The bigquery remote function capable of calling into `bigframes_cloud_function`.
13821382
"""
1383-
return self._remote_function_session.remote_function(
1383+
return self._function_session.remote_function(
13841384
input_types,
13851385
output_type,
13861386
session=self,
@@ -1556,7 +1556,7 @@ def read_gbq_function(
15561556
not including the `bigframes_cloud_function` property.
15571557
"""
15581558

1559-
return bigframes_rf.read_gbq_function(
1559+
return bff.read_gbq_function(
15601560
function_name=function_name,
15611561
session=self,
15621562
is_row_processor=is_row_processor,

tests/system/large/test_remote_function.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
import bigframes.dataframe
3333
import bigframes.dtypes
3434
import bigframes.exceptions
35-
import bigframes.functions._utils as functions_utils
35+
import bigframes.functions._utils as bff_utils
3636
import bigframes.pandas as bpd
3737
import bigframes.series
3838
from tests.system.utils import (
@@ -633,11 +633,9 @@ def add_one(x):
633633
add_one_uniq, add_one_uniq_dir = make_uniq_udf(add_one)
634634

635635
# Expected cloud function name for the unique udf
636-
package_requirements = functions_utils._get_updated_package_requirements()
637-
add_one_uniq_hash = functions_utils._get_hash(
638-
add_one_uniq, package_requirements
639-
)
640-
add_one_uniq_cf_name = functions_utils.get_cloud_function_name(
636+
package_requirements = bff_utils._get_updated_package_requirements()
637+
add_one_uniq_hash = bff_utils._get_hash(add_one_uniq, package_requirements)
638+
add_one_uniq_cf_name = bff_utils.get_cloud_function_name(
641639
add_one_uniq_hash, session.session_id
642640
)
643641

tests/system/small/test_remote_function.py

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525
import bigframes
2626
import bigframes.dtypes
2727
import bigframes.exceptions
28-
from bigframes.functions import _utils as rf_utils
29-
from bigframes.functions import remote_function as rf
28+
from bigframes.functions import _utils as bff_utils
29+
from bigframes.functions import function as bff
3030
from tests.system.utils import assert_pandas_df_equal
3131

3232
_prefixer = test_utils.prefixer.Prefixer("bigframes", "")
@@ -94,12 +94,12 @@ def get_rf_name(func, package_requirements=None, is_row_processor=False):
9494
"""Get a remote function name for testing given a udf."""
9595
# Augment user package requirements with any internal package
9696
# requirements
97-
package_requirements = rf_utils._get_updated_package_requirements(
97+
package_requirements = bff_utils._get_updated_package_requirements(
9898
package_requirements, is_row_processor
9999
)
100100

101101
# Compute a unique hash representing the user code
102-
function_hash = rf_utils._get_hash(func, package_requirements)
102+
function_hash = bff_utils._get_hash(func, package_requirements)
103103

104104
return f"bigframes_{function_hash}"
105105

@@ -117,7 +117,7 @@ def test_remote_function_direct_no_session_param(
117117
def square(x):
118118
return x * x
119119

120-
square = rf.remote_function(
120+
square = bff.remote_function(
121121
int,
122122
int,
123123
bigquery_client=bigquery_client,
@@ -176,7 +176,7 @@ def test_remote_function_direct_no_session_param_location_specified(
176176
def square(x):
177177
return x * x
178178

179-
square = rf.remote_function(
179+
square = bff.remote_function(
180180
int,
181181
int,
182182
bigquery_client=bigquery_client,
@@ -235,7 +235,7 @@ def square(x):
235235
ValueError,
236236
match=re.escape("The location does not match BigQuery connection location:"),
237237
):
238-
rf.remote_function(
238+
bff.remote_function(
239239
int,
240240
int,
241241
bigquery_client=bigquery_client,
@@ -263,7 +263,7 @@ def test_remote_function_direct_no_session_param_location_project_specified(
263263
def square(x):
264264
return x * x
265265

266-
square = rf.remote_function(
266+
square = bff.remote_function(
267267
int,
268268
int,
269269
bigquery_client=bigquery_client,
@@ -324,7 +324,7 @@ def square(x):
324324
"The project_id does not match BigQuery connection gcp_project_id:"
325325
),
326326
):
327-
rf.remote_function(
327+
bff.remote_function(
328328
int,
329329
int,
330330
bigquery_client=bigquery_client,
@@ -346,7 +346,7 @@ def test_remote_function_direct_session_param(
346346
def square(x):
347347
return x * x
348348

349-
square = rf.remote_function(
349+
square = bff.remote_function(
350350
int,
351351
int,
352352
session=session_with_bq_connection,
@@ -636,7 +636,7 @@ def add_one(x):
636636
def test_read_gbq_function_detects_invalid_function(session, dataset_id):
637637
dataset_ref = bigquery.DatasetReference.from_string(dataset_id)
638638
with pytest.raises(ValueError) as e:
639-
rf.read_gbq_function(
639+
bff.read_gbq_function(
640640
str(dataset_ref.routine("not_a_function")),
641641
session=session,
642642
)
@@ -658,7 +658,7 @@ def test_read_gbq_function_like_original(
658658
def square1(x):
659659
return x * x
660660

661-
square1 = rf.remote_function(
661+
square1 = bff.remote_function(
662662
[int],
663663
int,
664664
bigquery_client=bigquery_client,
@@ -674,7 +674,7 @@ def square1(x):
674674
# Function should still work normally.
675675
assert square1(2) == 4
676676

677-
square2 = rf.read_gbq_function(
677+
square2 = bff.read_gbq_function(
678678
function_name=square1.bigframes_remote_function, # type: ignore
679679
session=session,
680680
)
@@ -745,7 +745,7 @@ def test_read_gbq_function_reads_udfs(session, bigquery_client, dataset_id):
745745
for routine in (sql_routine, js_routine):
746746
# Create the routine in BigQuery and read it back using read_gbq_function.
747747
bigquery_client.create_routine(routine, exists_ok=True)
748-
square = rf.read_gbq_function(
748+
square = bff.read_gbq_function(
749749
str(routine.reference),
750750
session=session,
751751
)
@@ -757,7 +757,7 @@ def test_read_gbq_function_reads_udfs(session, bigquery_client, dataset_id):
757757

758758
src = {"x": [-5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5]}
759759

760-
routine_ref_str = rf_utils.routine_ref_to_string_for_query(routine.reference)
760+
routine_ref_str = bff_utils.routine_ref_to_string_for_query(routine.reference)
761761
direct_sql = " UNION ALL ".join(
762762
[f"SELECT {x} AS x, {routine_ref_str}({x}) AS y" for x in src["x"]]
763763
)
@@ -818,25 +818,25 @@ def test_read_gbq_function_requires_explicit_types(
818818
bigquery_client.create_routine(only_arg_type_specified, exists_ok=True)
819819
bigquery_client.create_routine(neither_type_specified, exists_ok=True)
820820

821-
rf.read_gbq_function(
821+
bff.read_gbq_function(
822822
str(both_types_specified.reference),
823823
session=session,
824824
)
825825
with pytest.warns(
826826
bigframes.exceptions.UnknownDataTypeWarning,
827827
match="missing input data types.*assume default data type",
828828
):
829-
rf.read_gbq_function(
829+
bff.read_gbq_function(
830830
str(only_return_type_specified.reference),
831831
session=session,
832832
)
833833
with pytest.raises(ValueError):
834-
rf.read_gbq_function(
834+
bff.read_gbq_function(
835835
str(only_arg_type_specified.reference),
836836
session=session,
837837
)
838838
with pytest.raises(ValueError):
839-
rf.read_gbq_function(
839+
bff.read_gbq_function(
840840
str(neither_type_specified.reference),
841841
session=session,
842842
)
@@ -878,13 +878,13 @@ def test_read_gbq_function_respects_python_output_type(
878878
body="TO_JSON_STRING([x, x+1, x+2])",
879879
arguments=[arg],
880880
return_type=bigquery.StandardSqlDataType(bigquery.StandardSqlTypeNames.STRING),
881-
description=rf_utils.get_bigframes_metadata(python_output_type=array_type),
881+
description=bff_utils.get_bigframes_metadata(python_output_type=array_type),
882882
type_=bigquery.RoutineType.SCALAR_FUNCTION,
883883
)
884884

885885
# Create the routine in BigQuery and read it back using read_gbq_function.
886886
bigquery_client.create_routine(sql_routine, exists_ok=True)
887-
func = rf.read_gbq_function(str(sql_routine.reference), session=session)
887+
func = bff.read_gbq_function(str(sql_routine.reference), session=session)
888888

889889
# test that the function works as expected
890890
s = bigframes.series.Series([1, 10, 100])
@@ -920,7 +920,7 @@ def test_read_gbq_function_supports_python_output_type_only_for_string_outputs(
920920
body="x+1",
921921
arguments=[arg],
922922
return_type=bigquery.StandardSqlDataType(bigquery.StandardSqlTypeNames.INT64),
923-
description=rf_utils.get_bigframes_metadata(python_output_type=array_type),
923+
description=bff_utils.get_bigframes_metadata(python_output_type=array_type),
924924
type_=bigquery.RoutineType.SCALAR_FUNCTION,
925925
)
926926

@@ -933,7 +933,7 @@ def test_read_gbq_function_supports_python_output_type_only_for_string_outputs(
933933
TypeError,
934934
match="An explicit output_type should be provided only for a BigQuery function with STRING output.",
935935
):
936-
rf.read_gbq_function(str(sql_routine.reference), session=session)
936+
bff.read_gbq_function(str(sql_routine.reference), session=session)
937937

938938

939939
@pytest.mark.parametrize(
@@ -959,13 +959,13 @@ def test_read_gbq_function_supported_python_output_type(
959959
body="CAST(x AS STRING)",
960960
arguments=[arg],
961961
return_type=bigquery.StandardSqlDataType(bigquery.StandardSqlTypeNames.STRING),
962-
description=rf_utils.get_bigframes_metadata(python_output_type=array_type),
962+
description=bff_utils.get_bigframes_metadata(python_output_type=array_type),
963963
type_=bigquery.RoutineType.SCALAR_FUNCTION,
964964
)
965965

966966
# Create the routine in BigQuery and read it back using read_gbq_function.
967967
bigquery_client.create_routine(sql_routine, exists_ok=True)
968-
rf.read_gbq_function(str(sql_routine.reference), session=session)
968+
bff.read_gbq_function(str(sql_routine.reference), session=session)
969969

970970

971971
@pytest.mark.flaky(retries=2, delay=120)

tests/system/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
import pyarrow as pa # type: ignore
2727
import pytest
2828

29-
import bigframes.functions._utils as functions_utils
29+
import bigframes.functions._utils as bff_utils
3030
import bigframes.pandas
3131

3232
ML_REGRESSION_METRICS = [
@@ -351,7 +351,7 @@ def get_cloud_functions(
351351
not name or not name_prefix
352352
), "Either 'name' or 'name_prefix' can be passed but not both."
353353

354-
_, location = functions_utils.get_remote_function_locations(location)
354+
_, location = bff_utils.get_remote_function_locations(location)
355355
parent = f"projects/{project}/locations/{location}"
356356
request = functions_v2.ListFunctionsRequest(parent=parent)
357357
page_result = functions_client.list_functions(request=request)

0 commit comments

Comments
 (0)