Skip to content

Commit 90e7d33

Browse files
committed
Revert "fix testcase"
This reverts commit 9a5bcd2.
1 parent 9a5bcd2 commit 90e7d33

File tree

4 files changed

+47
-52
lines changed

4 files changed

+47
-52
lines changed

bigframes/blob/_functions.py

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

217-
result_dict["content"] = dst_obj_ref_rt_json["objectref"]["uri"]
218-
219217
except Exception as e:
220218
result_dict["status"] = str(e)
221219

@@ -234,7 +232,8 @@ def image_blur_to_bytes_func(
234232
import base64
235233
import json
236234

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

239238
try:
240239
import cv2 as cv # type: ignore
@@ -258,12 +257,11 @@ def image_blur_to_bytes_func(
258257
img_blurred = cv.blur(img, ksize=(ksize_x, ksize_y))
259258
content = cv.imencode(ext, img_blurred)[1].tobytes()
260259

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

263+
encoded_content = base64.b64encode(content).decode("utf-8")
264+
result_dict = {"status": status, "content": encoded_content}
267265
if verbose:
268266
return json.dumps(result_dict)
269267
else:
@@ -329,8 +327,6 @@ def image_resize_func(
329327
timeout=30,
330328
)
331329

332-
result_dict["content"] = dst_obj_ref_rt_json["objectref"]["uri"]
333-
334330
except Exception as e:
335331
result_dict["status"] = str(e)
336332

@@ -357,7 +353,8 @@ def image_resize_to_bytes_func(
357353
import base64
358354
import json
359355

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

362359
try:
363360
import cv2 as cv # type: ignore
@@ -381,12 +378,11 @@ def image_resize_to_bytes_func(
381378
img_resized = cv.resize(img, dsize=(dsize_x, dsize_y), fx=fx, fy=fy)
382379
content = cv.imencode(".jpeg", img_resized)[1].tobytes()
383380

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

384+
encoded_content = base64.b64encode(content).decode("utf-8")
385+
result_dict = {"status": status, "content": encoded_content}
390386
if verbose:
391387
return json.dumps(result_dict)
392388
else:
@@ -460,8 +456,6 @@ def image_normalize_func(
460456
timeout=30,
461457
)
462458

463-
result_dict["content"] = dst_obj_ref_rt_json["objectref"]["uri"]
464-
465459
except Exception as e:
466460
result_dict["status"] = str(e)
467461

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[Union[int, float, str, Callable]]]
98+
MultiItemValue = Union["DataFrame", Sequence[int | float | str | Callable]]
9999

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

bigframes/operations/blob.py

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

1717
import os
18-
import typing
1918
from typing import cast, Literal, Optional, Union
2019
import warnings
2120

@@ -372,10 +371,7 @@ def image_blur(
372371
container_cpu: Union[float, int] = 0.33,
373372
container_memory: str = "512Mi",
374373
verbose: bool = False,
375-
) -> typing.Union[
376-
bigframes.series.Series,
377-
typing.Tuple[bigframes.series.Series, bigframes.series.Series],
378-
]:
374+
) -> bigframes.series.Series:
379375
"""Blurs images.
380376
381377
Args:
@@ -478,8 +474,11 @@ def image_blur(
478474
)
479475
content_series = res._apply_unary_op(ops.JSONValue(json_path="$.content"))
480476
dst_blobs = content_series.str.to_blob(connection=connection)
481-
482-
return dst_blobs, blurred_status_series
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
483482
else:
484483
return res.str.to_blob(connection=connection)
485484

@@ -632,10 +631,7 @@ def image_normalize(
632631
container_cpu: Union[float, int] = 0.33,
633632
container_memory: str = "512Mi",
634633
verbose: bool = False,
635-
) -> typing.Union[
636-
bigframes.series.Series,
637-
typing.Tuple[bigframes.series.Series, bigframes.series.Series],
638-
]:
634+
) -> bigframes.series.Series:
639635
"""Normalize images.
640636
641637
Args:
@@ -744,8 +740,14 @@ def image_normalize(
744740
)
745741
content_series = res._apply_unary_op(ops.JSONValue(json_path="$.content"))
746742
dst_blobs = content_series.str.to_blob(connection=connection)
747-
748-
return dst_blobs, normalized_status_series
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
749751
else:
750752
return res.str.to_blob(connection=connection)
751753

tests/system/large/blob/test_function.py

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@ 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()
124123

125124
else:
126125
expected_df = pd.DataFrame(
@@ -132,13 +131,14 @@ def test_blob_image_blur_to_series(
132131
}
133132
)
134133
pd.testing.assert_frame_equal(
135-
actual.blob.to_frame().to_pandas(),
134+
actual.struct.explode().to_pandas(),
136135
expected_df,
137136
check_dtype=False,
138137
check_index_type=False,
139138
)
140-
# verify the files exist
141-
assert not actual.blob.size().isna().any()
139+
140+
# verify the files exist
141+
assert not actual.blob.size().isna().any()
142142

143143

144144
@pytest.mark.parametrize("verbose", [True, False])
@@ -168,7 +168,6 @@ 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()
172171

173172
else:
174173
expected_df = pd.DataFrame(
@@ -180,13 +179,14 @@ def test_blob_image_blur_to_folder(
180179
}
181180
)
182181
pd.testing.assert_frame_equal(
183-
actual.blob.to_frame().to_pandas(),
182+
actual.struct.explode().to_pandas(),
184183
expected_df,
185184
check_dtype=False,
186185
check_index_type=False,
187186
)
188-
# verify the files exist
189-
assert not actual.blob.size().isna().any()
187+
188+
# verify the files exist
189+
assert not actual.blob.size().isna().any()
190190

191191

192192
@pytest.mark.parametrize("verbose", [True, False])
@@ -248,7 +248,6 @@ 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()
252251

253252
else:
254253
expected_df = pd.DataFrame(
@@ -260,13 +259,14 @@ def test_blob_image_resize_to_series(
260259
}
261260
)
262261
pd.testing.assert_frame_equal(
263-
actual.blob.to_frame().to_pandas(),
262+
actual.struct.explode().to_pandas(),
264263
expected_df,
265264
check_dtype=False,
266265
check_index_type=False,
267266
)
268-
# verify the files exist
269-
assert not actual.blob.size().isna().any()
267+
268+
# verify the files exist
269+
assert not actual.blob.size().isna().any()
270270

271271

272272
@pytest.mark.parametrize("verbose", [True, False])
@@ -297,7 +297,6 @@ 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()
301300

302301
else:
303302
expected_df = pd.DataFrame(
@@ -309,13 +308,14 @@ def test_blob_image_resize_to_folder(
309308
}
310309
)
311310
pd.testing.assert_frame_equal(
312-
actual.blob.to_frame().to_pandas(),
311+
actual.struct.explode().to_pandas(),
313312
expected_df,
314313
check_dtype=False,
315314
check_index_type=False,
316315
)
317-
# verify the files exist
318-
assert not actual.blob.size().isna().any()
316+
317+
# verify the files exist
318+
assert not actual.blob.size().isna().any()
319319

320320

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

370370
if verbose:
371+
371372
assert hasattr(actual, "struct")
372373
actual_exploded = actual.struct.explode()
373374
assert "status" in actual_exploded.columns
@@ -379,7 +380,6 @@ def test_blob_image_normalize_to_series(
379380
content_series = actual_exploded["content"]
380381
# Content should be blob objects for GCS destination
381382
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.blob.to_frame().to_pandas(),
394+
actual.struct.explode().to_pandas(),
395395
expected_df,
396396
check_dtype=False,
397397
check_index_type=False,
@@ -431,7 +431,6 @@ 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()
435434

436435
else:
437436
expected_df = pd.DataFrame(
@@ -443,14 +442,14 @@ def test_blob_image_normalize_to_folder(
443442
}
444443
)
445444
pd.testing.assert_frame_equal(
446-
actual.blob.to_frame().to_pandas(),
445+
actual.struct.explode().to_pandas(),
447446
expected_df,
448447
check_dtype=False,
449448
check_index_type=False,
450449
)
451450

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

455454

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

0 commit comments

Comments
 (0)