Skip to content

Commit 9ab240f

Browse files
committed
image function still have bug
1 parent e505e2f commit 9ab240f

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

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

120121

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

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

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

157155

158156
exif_func_def = FunctionDef(exif_func, ["pillow", "requests"])
@@ -165,7 +163,6 @@ def image_blur_func(
165163
ksize_x: int,
166164
ksize_y: int,
167165
ext: str,
168-
verbose: bool,
169166
) -> str:
170167
import json
171168

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

217-
if verbose:
218-
return json.dumps(result_dict)
219-
else:
220-
return result_dict["content"]
214+
return json.dumps(result_dict)
221215

222216

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

225219

226220
def image_blur_to_bytes_func(
227-
src_obj_ref_rt: str, ksize_x: int, ksize_y: int, ext: str, verbose: bool
221+
src_obj_ref_rt: str, ksize_x: int, ksize_y: int, ext: str
228222
) -> str:
229223
import base64
230224
import json
@@ -257,11 +251,8 @@ def image_blur_to_bytes_func(
257251
except Exception as e:
258252
status = str(e)
259253

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

266257

267258
image_blur_to_bytes_def = FunctionDef(
@@ -277,7 +268,6 @@ def image_resize_func(
277268
fx: float,
278269
fy: float,
279270
ext: str,
280-
verbose: bool,
281271
) -> str:
282272
import json
283273

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

329-
if verbose:
330-
return json.dumps(result_dict)
331-
else:
332-
return result_dict["content"]
319+
return json.dumps(result_dict)
333320

334321

335322
image_resize_def = FunctionDef(
@@ -344,7 +331,6 @@ def image_resize_to_bytes_func(
344331
fx: float,
345332
fy: float,
346333
ext: str,
347-
verbose: bool,
348334
) -> str:
349335
import base64
350336
import json
@@ -377,11 +363,8 @@ def image_resize_to_bytes_func(
377363
except Exception as e:
378364
status = str(e)
379365

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

386369

387370
image_resize_to_bytes_def = FunctionDef(
@@ -396,7 +379,6 @@ def image_normalize_func(
396379
beta: float,
397380
norm_type: str,
398381
ext: str,
399-
verbose: bool,
400382
) -> str:
401383
import json
402384

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

457-
if verbose:
458-
return json.dumps(result_dict)
459-
else:
460-
return result_dict["content"]
439+
return json.dumps(result_dict)
461440

462441

463442
image_normalize_def = FunctionDef(
@@ -471,7 +450,6 @@ def image_normalize_to_bytes_func(
471450
beta: float,
472451
norm_type: str,
473452
ext: str,
474-
verbose: bool,
475453
) -> str:
476454
import base64
477455
import json
@@ -515,10 +493,7 @@ def image_normalize_to_bytes_func(
515493
except Exception as e:
516494
result_dict["status"] = str(e)
517495

518-
if verbose:
519-
return json.dumps(result_dict)
520-
else:
521-
return result_dict["content"]
496+
return json.dumps(result_dict)
522497

523498

524499
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)