Skip to content

Commit 9a5bcd2

Browse files
committed
fix testcase
1 parent 3d58a60 commit 9a5bcd2

File tree

4 files changed

+52
-47
lines changed

4 files changed

+52
-47
lines changed

bigframes/blob/_functions.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,8 @@ def image_blur_func(
214214
timeout=30,
215215
)
216216

217+
result_dict["content"] = dst_obj_ref_rt_json["objectref"]["uri"]
218+
217219
except Exception as e:
218220
result_dict["status"] = str(e)
219221

@@ -232,8 +234,7 @@ def image_blur_to_bytes_func(
232234
import base64
233235
import json
234236

235-
status = ""
236-
content = b""
237+
result_dict = {"status": "", "content": ""}
237238

238239
try:
239240
import cv2 as cv # type: ignore
@@ -257,11 +258,12 @@ def image_blur_to_bytes_func(
257258
img_blurred = cv.blur(img, ksize=(ksize_x, ksize_y))
258259
content = cv.imencode(ext, img_blurred)[1].tobytes()
259260

261+
encoded_content = base64.b64encode(content).decode("utf-8")
262+
result_dict["content"] = encoded_content
263+
260264
except Exception as e:
261-
status = str(e)
265+
result_dict["status"] = str(e)
262266

263-
encoded_content = base64.b64encode(content).decode("utf-8")
264-
result_dict = {"status": status, "content": encoded_content}
265267
if verbose:
266268
return json.dumps(result_dict)
267269
else:
@@ -327,6 +329,8 @@ def image_resize_func(
327329
timeout=30,
328330
)
329331

332+
result_dict["content"] = dst_obj_ref_rt_json["objectref"]["uri"]
333+
330334
except Exception as e:
331335
result_dict["status"] = str(e)
332336

@@ -353,8 +357,7 @@ def image_resize_to_bytes_func(
353357
import base64
354358
import json
355359

356-
status = ""
357-
content = b""
360+
result_dict = {"status": "", "content": ""}
358361

359362
try:
360363
import cv2 as cv # type: ignore
@@ -378,11 +381,12 @@ def image_resize_to_bytes_func(
378381
img_resized = cv.resize(img, dsize=(dsize_x, dsize_y), fx=fx, fy=fy)
379382
content = cv.imencode(".jpeg", img_resized)[1].tobytes()
380383

384+
encoded_content = base64.b64encode(content).decode("utf-8")
385+
result_dict["content"] = encoded_content
386+
381387
except Exception as e:
382-
status = str(e)
388+
result_dict["status"] = str(e)
383389

384-
encoded_content = base64.b64encode(content).decode("utf-8")
385-
result_dict = {"status": status, "content": encoded_content}
386390
if verbose:
387391
return json.dumps(result_dict)
388392
else:
@@ -456,6 +460,8 @@ def image_normalize_func(
456460
timeout=30,
457461
)
458462

463+
result_dict["content"] = dst_obj_ref_rt_json["objectref"]["uri"]
464+
459465
except Exception as e:
460466
result_dict["status"] = str(e)
461467

bigframes/dataframe.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@
9595
import bigframes.session
9696

9797
SingleItemValue = Union[bigframes.series.Series, int, float, str, Callable]
98-
MultiItemValue = Union["DataFrame", Sequence[int | float | str | Callable]]
98+
MultiItemValue = Union["DataFrame", Sequence[Union[int, float, str, Callable]]]
9999

100100
LevelType = typing.Hashable
101101
LevelsType = typing.Union[LevelType, typing.Sequence[LevelType]]

bigframes/operations/blob.py

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from __future__ import annotations
1616

1717
import os
18+
import typing
1819
from typing import cast, Literal, Optional, Union
1920
import warnings
2021

@@ -371,7 +372,10 @@ def image_blur(
371372
container_cpu: Union[float, int] = 0.33,
372373
container_memory: str = "512Mi",
373374
verbose: bool = False,
374-
) -> bigframes.series.Series:
375+
) -> typing.Union[
376+
bigframes.series.Series,
377+
typing.Tuple[bigframes.series.Series, bigframes.series.Series],
378+
]:
375379
"""Blurs images.
376380
377381
Args:
@@ -474,11 +478,8 @@ def image_blur(
474478
)
475479
content_series = res._apply_unary_op(ops.JSONValue(json_path="$.content"))
476480
dst_blobs = content_series.str.to_blob(connection=connection)
477-
results_df = bpd.DataFrame(
478-
{"status": blurred_status_series, "content": dst_blobs}
479-
)
480-
results_struct = bbq.struct(results_df).rename("blurred_results")
481-
return results_struct
481+
482+
return dst_blobs, blurred_status_series
482483
else:
483484
return res.str.to_blob(connection=connection)
484485

@@ -631,7 +632,10 @@ def image_normalize(
631632
container_cpu: Union[float, int] = 0.33,
632633
container_memory: str = "512Mi",
633634
verbose: bool = False,
634-
) -> bigframes.series.Series:
635+
) -> typing.Union[
636+
bigframes.series.Series,
637+
typing.Tuple[bigframes.series.Series, bigframes.series.Series],
638+
]:
635639
"""Normalize images.
636640
637641
Args:
@@ -740,14 +744,8 @@ def image_normalize(
740744
)
741745
content_series = res._apply_unary_op(ops.JSONValue(json_path="$.content"))
742746
dst_blobs = content_series.str.to_blob(connection=connection)
743-
results_df = bpd.DataFrame(
744-
{
745-
"status": normalized_status_series,
746-
"content": dst_blobs,
747-
}
748-
)
749-
results_struct = bbq.struct(results_df).rename("normalized_results")
750-
return results_struct
747+
748+
return dst_blobs, normalized_status_series
751749
else:
752750
return res.str.to_blob(connection=connection)
753751

tests/system/large/blob/test_function.py

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ def test_blob_image_blur_to_series(
120120
content_series = actual_exploded["content"]
121121
# Content should be blob objects for GCS destination
122122
assert hasattr(content_series, "blob")
123+
assert not content_series.blob.size().isna().any()
123124

124125
else:
125126
expected_df = pd.DataFrame(
@@ -131,14 +132,13 @@ def test_blob_image_blur_to_series(
131132
}
132133
)
133134
pd.testing.assert_frame_equal(
134-
actual.struct.explode().to_pandas(),
135+
actual.blob.to_frame().to_pandas(),
135136
expected_df,
136137
check_dtype=False,
137138
check_index_type=False,
138139
)
139-
140-
# verify the files exist
141-
assert not actual.blob.size().isna().any()
140+
# verify the files exist
141+
assert not actual.blob.size().isna().any()
142142

143143

144144
@pytest.mark.parametrize("verbose", [True, False])
@@ -168,6 +168,7 @@ def test_blob_image_blur_to_folder(
168168
content_series = actual_exploded["content"]
169169
# Content should be blob objects for GCS destination
170170
assert hasattr(content_series, "blob")
171+
assert not content_series.blob.size().isna().any()
171172

172173
else:
173174
expected_df = pd.DataFrame(
@@ -179,14 +180,13 @@ def test_blob_image_blur_to_folder(
179180
}
180181
)
181182
pd.testing.assert_frame_equal(
182-
actual.struct.explode().to_pandas(),
183+
actual.blob.to_frame().to_pandas(),
183184
expected_df,
184185
check_dtype=False,
185186
check_index_type=False,
186187
)
187-
188-
# verify the files exist
189-
assert not actual.blob.size().isna().any()
188+
# verify the files exist
189+
assert not actual.blob.size().isna().any()
190190

191191

192192
@pytest.mark.parametrize("verbose", [True, False])
@@ -248,6 +248,7 @@ def test_blob_image_resize_to_series(
248248
content_series = actual_exploded["content"]
249249
# Content should be blob objects for GCS destination
250250
assert hasattr(content_series, "blob")
251+
assert not content_series.blob.size().isna().any()
251252

252253
else:
253254
expected_df = pd.DataFrame(
@@ -259,14 +260,13 @@ def test_blob_image_resize_to_series(
259260
}
260261
)
261262
pd.testing.assert_frame_equal(
262-
actual.struct.explode().to_pandas(),
263+
actual.blob.to_frame().to_pandas(),
263264
expected_df,
264265
check_dtype=False,
265266
check_index_type=False,
266267
)
267-
268-
# verify the files exist
269-
assert not actual.blob.size().isna().any()
268+
# verify the files exist
269+
assert not actual.blob.size().isna().any()
270270

271271

272272
@pytest.mark.parametrize("verbose", [True, False])
@@ -297,6 +297,7 @@ def test_blob_image_resize_to_folder(
297297
content_series = actual_exploded["content"]
298298
# Content should be blob objects for GCS destination
299299
assert hasattr(content_series, "blob")
300+
assert not content_series.blob.size().isna().any()
300301

301302
else:
302303
expected_df = pd.DataFrame(
@@ -308,14 +309,13 @@ def test_blob_image_resize_to_folder(
308309
}
309310
)
310311
pd.testing.assert_frame_equal(
311-
actual.struct.explode().to_pandas(),
312+
actual.blob.to_frame().to_pandas(),
312313
expected_df,
313314
check_dtype=False,
314315
check_index_type=False,
315316
)
316-
317-
# verify the files exist
318-
assert not actual.blob.size().isna().any()
317+
# verify the files exist
318+
assert not actual.blob.size().isna().any()
319319

320320

321321
@pytest.mark.parametrize("verbose", [True, False])
@@ -368,7 +368,6 @@ def test_blob_image_normalize_to_series(
368368
)
369369

370370
if verbose:
371-
372371
assert hasattr(actual, "struct")
373372
actual_exploded = actual.struct.explode()
374373
assert "status" in actual_exploded.columns
@@ -380,6 +379,7 @@ def test_blob_image_normalize_to_series(
380379
content_series = actual_exploded["content"]
381380
# Content should be blob objects for GCS destination
382381
assert hasattr(content_series, "blob")
382+
assert not content_series.blob.size().isna().any()
383383

384384
else:
385385
expected_df = pd.DataFrame(
@@ -391,7 +391,7 @@ def test_blob_image_normalize_to_series(
391391
}
392392
)
393393
pd.testing.assert_frame_equal(
394-
actual.struct.explode().to_pandas(),
394+
actual.blob.to_frame().to_pandas(),
395395
expected_df,
396396
check_dtype=False,
397397
check_index_type=False,
@@ -431,6 +431,7 @@ def test_blob_image_normalize_to_folder(
431431
content_series = actual_exploded["content"]
432432
# Content should be blob objects for GCS destination
433433
assert hasattr(content_series, "blob")
434+
assert not content_series.blob.size().isna().any()
434435

435436
else:
436437
expected_df = pd.DataFrame(
@@ -442,14 +443,14 @@ def test_blob_image_normalize_to_folder(
442443
}
443444
)
444445
pd.testing.assert_frame_equal(
445-
actual.struct.explode().to_pandas(),
446+
actual.blob.to_frame().to_pandas(),
446447
expected_df,
447448
check_dtype=False,
448449
check_index_type=False,
449450
)
450451

451-
# verify the files exist
452-
assert not actual.blob.size().isna().any()
452+
# verify the files exist
453+
assert not actual.blob.size().isna().any()
453454

454455

455456
@pytest.mark.parametrize("verbose", [True, False])

0 commit comments

Comments
 (0)