Skip to content

Commit 66e137e

Browse files
authored
chore: add experimental blob image_blur tests (#1482)
1 parent 5273d36 commit 66e137e

File tree

3 files changed

+149
-42
lines changed

3 files changed

+149
-42
lines changed

tests/system/conftest.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1436,3 +1436,27 @@ def cleanup_cloud_functions(session, cloudfunctions_client, dataset_id_permanent
14361436
#
14371437
# Let's stop further clean up and leave it to later.
14381438
traceback.print_exception(type(exc), exc, None)
1439+
1440+
1441+
@pytest.fixture(scope="session")
1442+
def images_gcs_path() -> str:
1443+
return "gs://bigframes_blob_test/images/*"
1444+
1445+
1446+
@pytest.fixture(scope="session")
1447+
def images_uris() -> list[str]:
1448+
return [
1449+
"gs://bigframes_blob_test/images/img0.jpg",
1450+
"gs://bigframes_blob_test/images/img1.jpg",
1451+
]
1452+
1453+
1454+
@pytest.fixture(scope="session")
1455+
def images_mm_df(
1456+
images_gcs_path, session: bigframes.Session, bq_connection: str
1457+
) -> bpd.DataFrame:
1458+
bigframes.options.experiments.blob = True
1459+
1460+
return session.from_glob_path(
1461+
images_gcs_path, name="blob_col", connection=bq_connection
1462+
)
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
# Copyright 2025 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import os
16+
import traceback
17+
from typing import Generator
18+
import uuid
19+
20+
from google.cloud import storage
21+
import pandas as pd
22+
import pytest
23+
24+
import bigframes
25+
from bigframes import dtypes
26+
import bigframes.pandas as bpd
27+
28+
29+
@pytest.fixture(scope="session")
30+
def images_output_folder() -> Generator[str, None, None]:
31+
id = uuid.uuid4().hex
32+
folder = os.path.join("gs://bigframes_blob_test/", id)
33+
yield folder
34+
35+
# clean up
36+
try:
37+
cloud_storage_client = storage.Client()
38+
bucket = cloud_storage_client.bucket("bigframes_blob_test")
39+
blobs = bucket.list_blobs(prefix=id)
40+
for blob in blobs:
41+
blob.delete()
42+
except Exception as exc:
43+
traceback.print_exception(type(exc), exc, None)
44+
45+
46+
@pytest.fixture(scope="session")
47+
def images_output_uris(images_output_folder: str) -> list[str]:
48+
return [
49+
os.path.join(images_output_folder, "img0.jpg"),
50+
os.path.join(images_output_folder, "img1.jpg"),
51+
]
52+
53+
54+
def test_blob_image_blur_to_series(
55+
images_mm_df: bpd.DataFrame,
56+
bq_connection: str,
57+
images_output_uris: list[str],
58+
session: bigframes.Session,
59+
):
60+
bigframes.options.experiments.blob = True
61+
62+
series = bpd.Series(images_output_uris, session=session).str.to_blob(
63+
connection=bq_connection
64+
)
65+
66+
actual = images_mm_df["blob_col"].blob.image_blur(
67+
(8, 8), dst=series, connection=bq_connection
68+
)
69+
expected_df = pd.DataFrame(
70+
{
71+
"uri": images_output_uris,
72+
"version": [None, None],
73+
"authorizer": [bq_connection.casefold(), bq_connection.casefold()],
74+
"details": [None, None],
75+
}
76+
)
77+
pd.testing.assert_frame_equal(
78+
actual.struct.explode().to_pandas(),
79+
expected_df,
80+
check_dtype=False,
81+
check_index_type=False,
82+
)
83+
84+
# verify the files exist
85+
assert not actual.blob.size().isna().any()
86+
87+
88+
def test_blob_image_blur_to_folder(
89+
images_mm_df: bpd.DataFrame,
90+
bq_connection: str,
91+
images_output_folder: str,
92+
images_output_uris: list[str],
93+
):
94+
bigframes.options.experiments.blob = True
95+
96+
actual = images_mm_df["blob_col"].blob.image_blur(
97+
(8, 8), dst=images_output_folder, connection=bq_connection
98+
)
99+
expected_df = pd.DataFrame(
100+
{
101+
"uri": images_output_uris,
102+
"version": [None, None],
103+
"authorizer": [bq_connection.casefold(), bq_connection.casefold()],
104+
"details": [None, None],
105+
}
106+
)
107+
pd.testing.assert_frame_equal(
108+
actual.struct.explode().to_pandas(),
109+
expected_df,
110+
check_dtype=False,
111+
check_index_type=False,
112+
)
113+
114+
# verify the files exist
115+
assert not actual.blob.size().isna().any()
116+
117+
118+
def test_blob_image_blur_to_bq(images_mm_df: bpd.DataFrame, bq_connection: str):
119+
bigframes.options.experiments.blob = True
120+
121+
actual = images_mm_df["blob_col"].blob.image_blur((8, 8), connection=bq_connection)
122+
123+
assert isinstance(actual, bpd.Series)
124+
assert len(actual) == 2
125+
assert actual.dtype == dtypes.BYTES_DTYPE

tests/system/small/blob/conftest.py

Lines changed: 0 additions & 42 deletions
This file was deleted.

0 commit comments

Comments
 (0)