Skip to content

Commit de1b2f7

Browse files
cleanup
1 parent ae221f3 commit de1b2f7

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
lines changed

packages/bigframes/bigframes/functions/_function_session.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -854,11 +854,11 @@ def wrapper(func):
854854
msg = bfe.format_message("input_types=Series is in preview.")
855855
warnings.warn(msg, stacklevel=1, category=bfe.PreviewWarning)
856856

857-
if not name: # session-managed resource
857+
if not name: # session-owned resource - will be cleaned up automatically
858858
self._update_temp_artifacts(full_rf_name, "")
859859
return bq_functions.UdfRoutine(func=func, _udf_def=udf_definition)
860860

861-
# user-managed permanent resource
861+
# user-managed permanent resource - will not be cleaned up automatically
862862
else:
863863
return bq_functions.BigqueryCallableRoutine(
864864
udf_definition, session, local_func=func, is_managed=True

packages/bigframes/bigframes/functions/function.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,6 @@
1717
import logging
1818
from typing import Callable, Optional, Protocol, runtime_checkable, TYPE_CHECKING
1919

20-
if TYPE_CHECKING:
21-
from bigframes.session import Session
22-
import bigframes.series
23-
2420
import dataclasses
2521

2622
import google.api_core.exceptions
@@ -32,6 +28,8 @@
3228

3329
if TYPE_CHECKING:
3430
import bigframes.core.col
31+
from bigframes.session import Session
32+
import bigframes.series
3533

3634
logger = logging.getLogger(__name__)
3735

@@ -158,6 +156,12 @@ def read_gbq_function(
158156

159157
@runtime_checkable
160158
class Udf(Protocol):
159+
"""
160+
Protocol for all BigFrames user-defined functions.
161+
162+
Has @runtime_checkable so functions like df.apply() can dispatch UDFs with isinstance() checks.
163+
"""
164+
161165
@property
162166
def udf_def(self) -> udf_def.BigqueryUdf: ...
163167

packages/bigframes/bigframes/functions/function_template.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def convert_from_bq_json(type_, arg):
4343
import base64
4444
import collections
4545

46-
converters = collections.defaultdict(lambda: (lambda value: value)) # type: ignore
46+
converters = collections.defaultdict(lambda: lambda value: value) # type: ignore
4747
converters["BYTES"] = base64.b64decode
4848
converter = converters[type_]
4949
return converter(arg) if arg is not None else None
@@ -53,7 +53,7 @@ def convert_to_bq_json(type_, arg):
5353
import base64
5454
import collections
5555

56-
converters = collections.defaultdict(lambda: (lambda value: value)) # type: ignore
56+
converters = collections.defaultdict(lambda: lambda value: value) # type: ignore
5757
converters["BYTES"] = lambda value: base64.b64encode(value).decode("utf-8")
5858
converter = converters[type_]
5959
return converter(arg) if arg is not None else None

0 commit comments

Comments
 (0)