Skip to content

Commit 5a399cf

Browse files
committed
Revert "fix testcase"
This reverts commit 9a5bcd2.
1 parent 671dd96 commit 5a399cf

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
@@ -215,8 +215,6 @@ def image_blur_func(
215215
timeout=30,
216216
)
217217

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

@@ -235,7 +233,8 @@ def image_blur_to_bytes_func(
235233
import base64
236234
import json
237235

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

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

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

264+
encoded_content = base64.b64encode(content).decode("utf-8")
265+
result_dict = {"status": status, "content": encoded_content}
268266
if verbose:
269267
return json.dumps(result_dict)
270268
else:
@@ -330,8 +328,6 @@ def image_resize_func(
330328
timeout=30,
331329
)
332330

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

@@ -358,7 +354,8 @@ def image_resize_to_bytes_func(
358354
import base64
359355
import json
360356

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

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

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

385+
encoded_content = base64.b64encode(content).decode("utf-8")
386+
result_dict = {"status": status, "content": encoded_content}
391387
if verbose:
392388
return json.dumps(result_dict)
393389
else:
@@ -461,8 +457,6 @@ def image_normalize_func(
461457
timeout=30,
462458
)
463459

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

bigframes/dataframe.py

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

9898
SingleItemValue = Union[bigframes.series.Series, int, float, str, Callable]
99-
MultiItemValue = Union["DataFrame", Sequence[Union[int, float, str, Callable]]]
99+
MultiItemValue = Union["DataFrame", Sequence[int | float | str | Callable]]
100100

101101
LevelType = typing.Hashable
102102
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
@@ -121,7 +121,6 @@ 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()
125124

126125
else:
127126
expected_df = pd.DataFrame(
@@ -133,13 +132,14 @@ def test_blob_image_blur_to_series(
133132
}
134133
)
135134
pd.testing.assert_frame_equal(
136-
actual.blob.to_frame().to_pandas(),
135+
actual.struct.explode().to_pandas(),
137136
expected_df,
138137
check_dtype=False,
139138
check_index_type=False,
140139
)
141-
# verify the files exist
142-
assert not actual.blob.size().isna().any()
140+
141+
# verify the files exist
142+
assert not actual.blob.size().isna().any()
143143

144144

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

174173
else:
175174
expected_df = pd.DataFrame(
@@ -181,13 +180,14 @@ def test_blob_image_blur_to_folder(
181180
}
182181
)
183182
pd.testing.assert_frame_equal(
184-
actual.blob.to_frame().to_pandas(),
183+
actual.struct.explode().to_pandas(),
185184
expected_df,
186185
check_dtype=False,
187186
check_index_type=False,
188187
)
189-
# verify the files exist
190-
assert not actual.blob.size().isna().any()
188+
189+
# verify the files exist
190+
assert not actual.blob.size().isna().any()
191191

192192

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

254253
else:
255254
expected_df = pd.DataFrame(
@@ -261,13 +260,14 @@ def test_blob_image_resize_to_series(
261260
}
262261
)
263262
pd.testing.assert_frame_equal(
264-
actual.blob.to_frame().to_pandas(),
263+
actual.struct.explode().to_pandas(),
265264
expected_df,
266265
check_dtype=False,
267266
check_index_type=False,
268267
)
269-
# verify the files exist
270-
assert not actual.blob.size().isna().any()
268+
269+
# verify the files exist
270+
assert not actual.blob.size().isna().any()
271271

272272

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

303302
else:
304303
expected_df = pd.DataFrame(
@@ -310,13 +309,14 @@ def test_blob_image_resize_to_folder(
310309
}
311310
)
312311
pd.testing.assert_frame_equal(
313-
actual.blob.to_frame().to_pandas(),
312+
actual.struct.explode().to_pandas(),
314313
expected_df,
315314
check_dtype=False,
316315
check_index_type=False,
317316
)
318-
# verify the files exist
319-
assert not actual.blob.size().isna().any()
317+
318+
# verify the files exist
319+
assert not actual.blob.size().isna().any()
320320

321321

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

371371
if verbose:
372+
372373
assert hasattr(actual, "struct")
373374
actual_exploded = actual.struct.explode()
374375
assert "status" in actual_exploded.columns
@@ -380,7 +381,6 @@ def test_blob_image_normalize_to_series(
380381
content_series = actual_exploded["content"]
381382
# Content should be blob objects for GCS destination
382383
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.blob.to_frame().to_pandas(),
395+
actual.struct.explode().to_pandas(),
396396
expected_df,
397397
check_dtype=False,
398398
check_index_type=False,
@@ -432,7 +432,6 @@ 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()
436435

437436
else:
438437
expected_df = pd.DataFrame(
@@ -444,14 +443,14 @@ def test_blob_image_normalize_to_folder(
444443
}
445444
)
446445
pd.testing.assert_frame_equal(
447-
actual.blob.to_frame().to_pandas(),
446+
actual.struct.explode().to_pandas(),
448447
expected_df,
449448
check_dtype=False,
450449
check_index_type=False,
451450
)
452451

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

456455

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

0 commit comments

Comments
 (0)