Skip to content

Commit 5d4b36e

Browse files
committed
image function still have bug
1 parent afd0b0d commit 5d4b36e

File tree

3 files changed

+16
-58
lines changed

3 files changed

+16
-58
lines changed

bigframes/blob/_functions.py

Lines changed: 12 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
float: "FLOAT64",
2727
str: "STRING",
2828
bytes: "BYTES",
29+
bool: "BOOL",
2930
}
3031

3132

@@ -117,7 +118,7 @@ def udf(self):
117118
return self._session.read_gbq_function(udf_name)
118119

119120

120-
def exif_func(src_obj_ref_rt: str, verbose: bool) -> str:
121+
def exif_func(src_obj_ref_rt: str) -> str:
121122
import io
122123
import json
123124

@@ -148,10 +149,7 @@ def exif_func(src_obj_ref_rt: str, verbose: bool) -> str:
148149
except Exception as e:
149150
result_dict["status"] = str(e)
150151

151-
if verbose:
152-
return json.dumps(result_dict)
153-
else:
154-
return result_dict["content"]
152+
return json.dumps(result_dict)
155153

156154

157155
exif_func_def = FunctionDef(exif_func, ["pillow", "requests"])
@@ -164,7 +162,6 @@ def image_blur_func(
164162
ksize_x: int,
165163
ksize_y: int,
166164
ext: str,
167-
verbose: bool,
168165
) -> str:
169166
import json
170167

@@ -213,17 +210,14 @@ def image_blur_func(
213210
except Exception as e:
214211
result_dict["status"] = str(e)
215212

216-
if verbose:
217-
return json.dumps(result_dict)
218-
else:
219-
return result_dict["content"]
213+
return json.dumps(result_dict)
220214

221215

222216
image_blur_def = FunctionDef(image_blur_func, ["opencv-python", "numpy", "requests"])
223217

224218

225219
def image_blur_to_bytes_func(
226-
src_obj_ref_rt: str, ksize_x: int, ksize_y: int, ext: str, verbose: bool
220+
src_obj_ref_rt: str, ksize_x: int, ksize_y: int, ext: str
227221
) -> str:
228222
import base64
229223
import json
@@ -256,11 +250,8 @@ def image_blur_to_bytes_func(
256250
except Exception as e:
257251
status = str(e)
258252

259-
if verbose:
260-
encoded_content = base64.b64encode(content).decode("utf-8")
261-
return json.dumps({"status": status, "content": encoded_content})
262-
else:
263-
return base64.b64encode(content).decode("utf-8")
253+
encoded_content = base64.b64encode(content).decode("utf-8")
254+
return json.dumps({"status": status, "content": encoded_content})
264255

265256

266257
image_blur_to_bytes_def = FunctionDef(
@@ -276,7 +267,6 @@ def image_resize_func(
276267
fx: float,
277268
fy: float,
278269
ext: str,
279-
verbose: bool,
280270
) -> str:
281271
import json
282272

@@ -325,10 +315,7 @@ def image_resize_func(
325315
except Exception as e:
326316
result_dict["status"] = str(e)
327317

328-
if verbose:
329-
return json.dumps(result_dict)
330-
else:
331-
return result_dict["content"]
318+
return json.dumps(result_dict)
332319

333320

334321
image_resize_def = FunctionDef(
@@ -343,7 +330,6 @@ def image_resize_to_bytes_func(
343330
fx: float,
344331
fy: float,
345332
ext: str,
346-
verbose: bool,
347333
) -> str:
348334
import base64
349335
import json
@@ -376,11 +362,8 @@ def image_resize_to_bytes_func(
376362
except Exception as e:
377363
status = str(e)
378364

379-
if verbose:
380-
encoded_content = base64.b64encode(content).decode("utf-8")
381-
return json.dumps({"status": status, "content": encoded_content})
382-
else:
383-
return base64.b64encode(content).decode("utf-8")
365+
encoded_content = base64.b64encode(content).decode("utf-8")
366+
return json.dumps({"status": status, "content": encoded_content})
384367

385368

386369
image_resize_to_bytes_def = FunctionDef(
@@ -395,7 +378,6 @@ def image_normalize_func(
395378
beta: float,
396379
norm_type: str,
397380
ext: str,
398-
verbose: bool,
399381
) -> str:
400382
import json
401383

@@ -453,10 +435,7 @@ def image_normalize_func(
453435
except Exception as e:
454436
result_dict["status"] = str(e)
455437

456-
if verbose:
457-
return json.dumps(result_dict)
458-
else:
459-
return result_dict["content"]
438+
return json.dumps(result_dict)
460439

461440

462441
image_normalize_def = FunctionDef(
@@ -470,7 +449,6 @@ def image_normalize_to_bytes_func(
470449
beta: float,
471450
norm_type: str,
472451
ext: str,
473-
verbose: bool,
474452
) -> str:
475453
import base64
476454
import json
@@ -514,10 +492,7 @@ def image_normalize_to_bytes_func(
514492
except Exception as e:
515493
result_dict["status"] = str(e)
516494

517-
if verbose:
518-
return json.dumps(result_dict)
519-
else:
520-
return result_dict["content"]
495+
return json.dumps(result_dict)
521496

522497

523498
image_normalize_to_bytes_def = FunctionDef(

bigframes/operations/blob.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,7 @@ def exif(
332332

333333
connection = self._resolve_connection(connection)
334334
df = self.get_runtime_json_str(mode="R").to_frame()
335+
df["verbose"] = verbose
335336

336337
exif_udf = blob_func.TransformFunction(
337338
blob_func.exif_func_def,

tests/system/large/blob/test_function.py

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,7 @@ def images_output_uris(images_output_folder: str) -> list[str]:
5151
]
5252

5353

54-
@pytest.mark.parametrize(
55-
"verbose",
56-
[
57-
(True),
58-
(False),
59-
],
60-
)
54+
@pytest.mark.parametrize("verbose", [True, False])
6155
def test_blob_exif(
6256
bq_connection: str,
6357
session: bigframes.Session,
@@ -489,13 +483,7 @@ def test_blob_image_normalize_to_bq(
489483
assert actual.dtype == dtypes.BYTES_DTYPE
490484

491485

492-
@pytest.mark.parametrize(
493-
"verbose",
494-
[
495-
(True),
496-
(False),
497-
],
498-
)
486+
@pytest.mark.parametrize("verbose", [True, False])
499487
def test_blob_pdf_extract(
500488
pdf_mm_df: bpd.DataFrame,
501489
verbose: bool,
@@ -538,13 +526,7 @@ def test_blob_pdf_extract(
538526
), f"Item (verbose={verbose}): Expected keyword '{keyword}' not found in extracted text. "
539527

540528

541-
@pytest.mark.parametrize(
542-
"verbose",
543-
[
544-
(True),
545-
(False),
546-
],
547-
)
529+
@pytest.mark.parametrize("verbose", [True, False])
548530
def test_blob_pdf_chunk(pdf_mm_df: bpd.DataFrame, verbose: bool, bq_connection: str):
549531
actual = (
550532
pdf_mm_df["pdf"]

0 commit comments

Comments
 (0)