Skip to content

Commit 671dd96

Browse files
committed
fix testcase
1 parent ba771aa commit 671dd96

File tree

4 files changed

+53
-52
lines changed

4 files changed

+53
-52
lines changed

bigframes/blob/_functions.py

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

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

@@ -233,8 +235,7 @@ def image_blur_to_bytes_func(
233235
import base64
234236
import json
235237

236-
status = ""
237-
content = b""
238+
result_dict = {"status": "", "content": ""}
238239

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

262+
encoded_content = base64.b64encode(content).decode("utf-8")
263+
result_dict["content"] = encoded_content
264+
261265
except Exception as e:
262-
status = str(e)
266+
result_dict["status"] = str(e)
263267

264-
encoded_content = base64.b64encode(content).decode("utf-8")
265-
result_dict = {"status": status, "content": encoded_content}
266268
if verbose:
267269
return json.dumps(result_dict)
268270
else:
@@ -328,6 +330,8 @@ def image_resize_func(
328330
timeout=30,
329331
)
330332

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

@@ -354,8 +358,7 @@ def image_resize_to_bytes_func(
354358
import base64
355359
import json
356360

357-
status = ""
358-
content = b""
361+
result_dict = {"status": "", "content": ""}
359362

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

385+
encoded_content = base64.b64encode(content).decode("utf-8")
386+
result_dict["content"] = encoded_content
387+
382388
except Exception as e:
383-
status = str(e)
389+
result_dict["status"] = str(e)
384390

385-
encoded_content = base64.b64encode(content).decode("utf-8")
386-
result_dict = {"status": status, "content": encoded_content}
387391
if verbose:
388392
return json.dumps(result_dict)
389393
else:
@@ -457,6 +461,8 @@ def image_normalize_func(
457461
timeout=30,
458462
)
459463

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

bigframes/dataframe.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,8 @@
9595

9696
import bigframes.session
9797

98-
SingleItemValue = Union[
99-
bigframes.series.Series, int, float, str, pandas.Timedelta, Callable
100-
]
101-
MultiItemValue = Union[
102-
"DataFrame", Sequence[int | float | str | pandas.Timedelta | Callable]
103-
]
98+
SingleItemValue = Union[bigframes.series.Series, int, float, str, Callable]
99+
MultiItemValue = Union["DataFrame", Sequence[Union[int, float, str, Callable]]]
104100

105101
LevelType = typing.Hashable
106102
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
@@ -121,6 +121,7 @@ def test_blob_image_blur_to_series(
121121
content_series = actual_exploded["content"]
122122
# Content should be blob objects for GCS destination
123123
assert hasattr(content_series, "blob")
124+
assert not content_series.blob.size().isna().any()
124125

125126
else:
126127
expected_df = pd.DataFrame(
@@ -132,14 +133,13 @@ def test_blob_image_blur_to_series(
132133
}
133134
)
134135
pd.testing.assert_frame_equal(
135-
actual.struct.explode().to_pandas(),
136+
actual.blob.to_frame().to_pandas(),
136137
expected_df,
137138
check_dtype=False,
138139
check_index_type=False,
139140
)
140-
141-
# verify the files exist
142-
assert not actual.blob.size().isna().any()
141+
# verify the files exist
142+
assert not actual.blob.size().isna().any()
143143

144144

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

173174
else:
174175
expected_df = pd.DataFrame(
@@ -180,14 +181,13 @@ def test_blob_image_blur_to_folder(
180181
}
181182
)
182183
pd.testing.assert_frame_equal(
183-
actual.struct.explode().to_pandas(),
184+
actual.blob.to_frame().to_pandas(),
184185
expected_df,
185186
check_dtype=False,
186187
check_index_type=False,
187188
)
188-
189-
# verify the files exist
190-
assert not actual.blob.size().isna().any()
189+
# verify the files exist
190+
assert not actual.blob.size().isna().any()
191191

192192

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

253254
else:
254255
expected_df = pd.DataFrame(
@@ -260,14 +261,13 @@ def test_blob_image_resize_to_series(
260261
}
261262
)
262263
pd.testing.assert_frame_equal(
263-
actual.struct.explode().to_pandas(),
264+
actual.blob.to_frame().to_pandas(),
264265
expected_df,
265266
check_dtype=False,
266267
check_index_type=False,
267268
)
268-
269-
# verify the files exist
270-
assert not actual.blob.size().isna().any()
269+
# verify the files exist
270+
assert not actual.blob.size().isna().any()
271271

272272

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

302303
else:
303304
expected_df = pd.DataFrame(
@@ -309,14 +310,13 @@ def test_blob_image_resize_to_folder(
309310
}
310311
)
311312
pd.testing.assert_frame_equal(
312-
actual.struct.explode().to_pandas(),
313+
actual.blob.to_frame().to_pandas(),
313314
expected_df,
314315
check_dtype=False,
315316
check_index_type=False,
316317
)
317-
318-
# verify the files exist
319-
assert not actual.blob.size().isna().any()
318+
# verify the files exist
319+
assert not actual.blob.size().isna().any()
320320

321321

322322
@pytest.mark.parametrize("verbose", [True, False])
@@ -369,7 +369,6 @@ def test_blob_image_normalize_to_series(
369369
)
370370

371371
if verbose:
372-
373372
assert hasattr(actual, "struct")
374373
actual_exploded = actual.struct.explode()
375374
assert "status" in actual_exploded.columns
@@ -381,6 +380,7 @@ def test_blob_image_normalize_to_series(
381380
content_series = actual_exploded["content"]
382381
# Content should be blob objects for GCS destination
383382
assert hasattr(content_series, "blob")
383+
assert not content_series.blob.size().isna().any()
384384

385385
else:
386386
expected_df = pd.DataFrame(
@@ -392,7 +392,7 @@ def test_blob_image_normalize_to_series(
392392
}
393393
)
394394
pd.testing.assert_frame_equal(
395-
actual.struct.explode().to_pandas(),
395+
actual.blob.to_frame().to_pandas(),
396396
expected_df,
397397
check_dtype=False,
398398
check_index_type=False,
@@ -432,6 +432,7 @@ def test_blob_image_normalize_to_folder(
432432
content_series = actual_exploded["content"]
433433
# Content should be blob objects for GCS destination
434434
assert hasattr(content_series, "blob")
435+
assert not content_series.blob.size().isna().any()
435436

436437
else:
437438
expected_df = pd.DataFrame(
@@ -443,14 +444,14 @@ def test_blob_image_normalize_to_folder(
443444
}
444445
)
445446
pd.testing.assert_frame_equal(
446-
actual.struct.explode().to_pandas(),
447+
actual.blob.to_frame().to_pandas(),
447448
expected_df,
448449
check_dtype=False,
449450
check_index_type=False,
450451
)
451452

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

455456

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

0 commit comments

Comments
 (0)