Skip to content

Commit 639c0a5

Browse files
committed
return None on error with verbose=False for image functions
1 parent 313f04a commit 639c0a5

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

bigframes/blob/_functions.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
from dataclasses import dataclass
1616
import inspect
17+
import typing
1718
from typing import Callable, Iterable, Union
1819

1920
import google.cloud.bigquery as bigquery
@@ -70,6 +71,12 @@ def _input_bq_signature(self):
7071

7172
def _output_bq_type(self):
7273
sig = inspect.signature(self._func)
74+
return_annotation = sig.return_annotation
75+
origin = typing.get_origin(return_annotation)
76+
if origin is Union:
77+
args = typing.get_args(return_annotation)
78+
if len(args) == 2 and args[1] is type(None):
79+
return _PYTHON_TO_BQ_TYPES[args[0]]
7380
return _PYTHON_TO_BQ_TYPES[sig.return_annotation]
7481

7582
def _create_udf(self):
@@ -177,7 +184,7 @@ def image_blur_func(
177184
ksize_y: int,
178185
ext: str,
179186
verbose: bool,
180-
) -> str:
187+
) -> typing.Optional[str]:
181188
try:
182189
import json
183190

@@ -241,9 +248,7 @@ def image_blur_func(
241248
if verbose:
242249
return json.dumps(error_result)
243250
else:
244-
# The calling function expects a json string that can be parsed as a blob ref
245-
# Return a valid blob ref json string with empty values.
246-
return '{"access_urls": {"read_url": "", "write_url": ""}, "authorizer": "", "generation": "", "uri": ""}'
251+
return None
247252

248253

249254
image_blur_def = FunctionDef(image_blur_func, ["opencv-python", "numpy", "requests"])
@@ -316,7 +321,7 @@ def image_resize_func(
316321
fy: float,
317322
ext: str,
318323
verbose: bool,
319-
) -> str:
324+
) -> typing.Optional[str]:
320325
try:
321326
import json
322327

@@ -379,9 +384,7 @@ def image_resize_func(
379384
if verbose:
380385
return json.dumps(error_result)
381386
else:
382-
# The calling function expects a json string that can be parsed as a blob ref
383-
# Return a valid blob ref json string with empty values.
384-
return '{"access_urls": {"read_url": "", "write_url": ""}, "authorizer": "", "generation": "", "uri": ""}'
387+
return None
385388

386389

387390
image_resize_def = FunctionDef(
@@ -461,7 +464,7 @@ def image_normalize_func(
461464
norm_type: str,
462465
ext: str,
463466
verbose: bool,
464-
) -> str:
467+
) -> typing.Optional[str]:
465468
try:
466469
import json
467470

@@ -533,9 +536,7 @@ def image_normalize_func(
533536
if verbose:
534537
return json.dumps(error_result)
535538
else:
536-
# The calling function expects a json string that can be parsed as a blob ref
537-
# Return a valid blob ref json string with empty values.
538-
return '{"access_urls": {"read_url": "", "write_url": ""}, "authorizer": "", "generation": "", "uri": ""}'
539+
return None
539540

540541

541542
image_normalize_def = FunctionDef(

0 commit comments

Comments
 (0)