Skip to content

Commit 59bd020

Browse files
committed
final touch
1 parent 6b68036 commit 59bd020

File tree

1 file changed

+42
-33
lines changed

1 file changed

+42
-33
lines changed

bigframes/blob/_functions.py

Lines changed: 42 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -255,9 +255,6 @@ def image_blur_to_bytes_func(
255255
import base64
256256
import json
257257

258-
status = ""
259-
content = b""
260-
261258
try:
262259
import cv2 as cv # type: ignore
263260
import numpy as np
@@ -288,15 +285,21 @@ def image_blur_to_bytes_func(
288285
raise ValueError(f"Failed to encode image with extension {ext}")
289286
content = encoded.tobytes()
290287

291-
except Exception as e:
292-
status = str(e)
288+
encoded_content = base64.b64encode(content).decode("utf-8")
289+
result_dict = {"status": "", "content": encoded_content}
290+
if verbose:
291+
return json.dumps(result_dict)
292+
else:
293+
return result_dict["content"]
293294

294-
encoded_content = base64.b64encode(content).decode("utf-8")
295-
result_dict = {"status": status, "content": encoded_content}
296-
if verbose:
297-
return json.dumps(result_dict)
298-
else:
299-
return result_dict["content"]
295+
except Exception as e:
296+
status = f"Error: {type(e).__name__}: {str(e)}"
297+
encoded_content = base64.b64encode(b"").decode("utf-8")
298+
result_dict = {"status": status, "content": encoded_content}
299+
if verbose:
300+
return json.dumps(result_dict)
301+
else:
302+
return result_dict["content"]
300303

301304

302305
image_blur_to_bytes_def = FunctionDef(
@@ -398,9 +401,6 @@ def image_resize_to_bytes_func(
398401
import base64
399402
import json
400403

401-
status = ""
402-
content = b""
403-
404404
try:
405405
import cv2 as cv # type: ignore
406406
import numpy as np
@@ -431,15 +431,21 @@ def image_resize_to_bytes_func(
431431
raise ValueError(f"Failed to encode image with extension {ext}")
432432
content = encoded.tobytes()
433433

434-
except Exception as e:
435-
status = str(e)
434+
encoded_content = base64.b64encode(content).decode("utf-8")
435+
result_dict = {"status": "", "content": encoded_content}
436+
if verbose:
437+
return json.dumps(result_dict)
438+
else:
439+
return result_dict["content"]
436440

437-
encoded_content = base64.b64encode(content).decode("utf-8")
438-
result_dict = {"status": status, "content": encoded_content}
439-
if verbose:
440-
return json.dumps(result_dict)
441-
else:
442-
return result_dict["content"]
441+
except Exception as e:
442+
status = f"Error: {type(e).__name__}: {str(e)}"
443+
encoded_content = base64.b64encode(b"").decode("utf-8")
444+
result_dict = {"status": status, "content": encoded_content}
445+
if verbose:
446+
return json.dumps(result_dict)
447+
else:
448+
return result_dict["content"]
443449

444450

445451
image_resize_to_bytes_def = FunctionDef(
@@ -548,9 +554,6 @@ def image_normalize_to_bytes_func(
548554
import base64
549555
import json
550556

551-
status = ""
552-
content = b""
553-
554557
try:
555558
import cv2 as cv # type: ignore
556559
import numpy as np
@@ -590,16 +593,22 @@ def image_normalize_to_bytes_func(
590593
raise ValueError(f"Failed to encode image with extension {ext}")
591594
content = encoded.tobytes()
592595

593-
except Exception as e:
594-
status = str(e)
596+
encoded_content = base64.b64encode(content).decode("utf-8")
597+
result_dict = {"status": "", "content": encoded_content}
595598

596-
encoded_content = base64.b64encode(content).decode("utf-8")
597-
result_dict = {"status": status, "content": encoded_content}
599+
if verbose:
600+
return json.dumps(result_dict)
601+
else:
602+
return result_dict["content"]
598603

599-
if verbose:
600-
return json.dumps(result_dict)
601-
else:
602-
return result_dict["content"]
604+
except Exception as e:
605+
status = f"Error: {type(e).__name__}: {str(e)}"
606+
encoded_content = base64.b64encode(b"").decode("utf-8")
607+
result_dict = {"status": status, "content": encoded_content}
608+
if verbose:
609+
return json.dumps(result_dict)
610+
else:
611+
return result_dict["content"]
603612

604613

605614
image_normalize_to_bytes_def = FunctionDef(

0 commit comments

Comments
 (0)