|
26 | 26 | import bigframes.pandas as bpd
|
27 | 27 |
|
28 | 28 |
|
29 |
| -@pytest.fixture(scope="session") |
| 29 | +@pytest.fixture(scope="function") |
30 | 30 | def images_output_folder() -> Generator[str, None, None]:
|
31 | 31 | id = uuid.uuid4().hex
|
32 |
| - folder = os.path.join("gs://bigframes_blob_test/", id) |
| 32 | + folder = os.path.join("gs://bigframes_blob_test/output/", id) |
33 | 33 | yield folder
|
34 | 34 |
|
35 | 35 | # clean up
|
36 | 36 | try:
|
37 | 37 | cloud_storage_client = storage.Client()
|
38 | 38 | bucket = cloud_storage_client.bucket("bigframes_blob_test")
|
39 |
| - blobs = bucket.list_blobs(prefix=id) |
| 39 | + blobs = bucket.list_blobs(prefix="output/" + id) |
40 | 40 | for blob in blobs:
|
41 | 41 | blob.delete()
|
42 | 42 | except Exception as exc:
|
43 | 43 | traceback.print_exception(type(exc), exc, None)
|
44 | 44 |
|
45 | 45 |
|
46 |
| -@pytest.fixture(scope="session") |
| 46 | +@pytest.fixture(scope="function") |
47 | 47 | def images_output_uris(images_output_folder: str) -> list[str]:
|
48 | 48 | return [
|
49 | 49 | os.path.join(images_output_folder, "img0.jpg"),
|
@@ -123,3 +123,159 @@ def test_blob_image_blur_to_bq(images_mm_df: bpd.DataFrame, bq_connection: str):
|
123 | 123 | assert isinstance(actual, bpd.Series)
|
124 | 124 | assert len(actual) == 2
|
125 | 125 | assert actual.dtype == dtypes.BYTES_DTYPE
|
| 126 | + |
| 127 | + |
| 128 | +def test_blob_image_resize_to_series( |
| 129 | + images_mm_df: bpd.DataFrame, |
| 130 | + bq_connection: str, |
| 131 | + images_output_uris: list[str], |
| 132 | + session: bigframes.Session, |
| 133 | +): |
| 134 | + bigframes.options.experiments.blob = True |
| 135 | + |
| 136 | + series = bpd.Series(images_output_uris, session=session).str.to_blob( |
| 137 | + connection=bq_connection |
| 138 | + ) |
| 139 | + |
| 140 | + actual = images_mm_df["blob_col"].blob.image_resize( |
| 141 | + (200, 300), dst=series, connection=bq_connection |
| 142 | + ) |
| 143 | + expected_df = pd.DataFrame( |
| 144 | + { |
| 145 | + "uri": images_output_uris, |
| 146 | + "version": [None, None], |
| 147 | + "authorizer": [bq_connection.casefold(), bq_connection.casefold()], |
| 148 | + "details": [None, None], |
| 149 | + } |
| 150 | + ) |
| 151 | + pd.testing.assert_frame_equal( |
| 152 | + actual.struct.explode().to_pandas(), |
| 153 | + expected_df, |
| 154 | + check_dtype=False, |
| 155 | + check_index_type=False, |
| 156 | + ) |
| 157 | + |
| 158 | + # verify the files exist |
| 159 | + assert not actual.blob.size().isna().any() |
| 160 | + |
| 161 | + |
| 162 | +def test_blob_image_resize_to_folder( |
| 163 | + images_mm_df: bpd.DataFrame, |
| 164 | + bq_connection: str, |
| 165 | + images_output_folder: str, |
| 166 | + images_output_uris: list[str], |
| 167 | +): |
| 168 | + bigframes.options.experiments.blob = True |
| 169 | + |
| 170 | + actual = images_mm_df["blob_col"].blob.image_resize( |
| 171 | + (200, 300), dst=images_output_folder, connection=bq_connection |
| 172 | + ) |
| 173 | + expected_df = pd.DataFrame( |
| 174 | + { |
| 175 | + "uri": images_output_uris, |
| 176 | + "version": [None, None], |
| 177 | + "authorizer": [bq_connection.casefold(), bq_connection.casefold()], |
| 178 | + "details": [None, None], |
| 179 | + } |
| 180 | + ) |
| 181 | + pd.testing.assert_frame_equal( |
| 182 | + actual.struct.explode().to_pandas(), |
| 183 | + expected_df, |
| 184 | + check_dtype=False, |
| 185 | + check_index_type=False, |
| 186 | + ) |
| 187 | + |
| 188 | + # verify the files exist |
| 189 | + assert not actual.blob.size().isna().any() |
| 190 | + |
| 191 | + |
| 192 | +def test_blob_image_resize_to_bq(images_mm_df: bpd.DataFrame, bq_connection: str): |
| 193 | + bigframes.options.experiments.blob = True |
| 194 | + |
| 195 | + actual = images_mm_df["blob_col"].blob.image_resize( |
| 196 | + (200, 300), connection=bq_connection |
| 197 | + ) |
| 198 | + |
| 199 | + assert isinstance(actual, bpd.Series) |
| 200 | + assert len(actual) == 2 |
| 201 | + assert actual.dtype == dtypes.BYTES_DTYPE |
| 202 | + |
| 203 | + |
| 204 | +def test_blob_image_normalize_to_series( |
| 205 | + images_mm_df: bpd.DataFrame, |
| 206 | + bq_connection: str, |
| 207 | + images_output_uris: list[str], |
| 208 | + session: bigframes.Session, |
| 209 | +): |
| 210 | + bigframes.options.experiments.blob = True |
| 211 | + |
| 212 | + series = bpd.Series(images_output_uris, session=session).str.to_blob( |
| 213 | + connection=bq_connection |
| 214 | + ) |
| 215 | + |
| 216 | + actual = images_mm_df["blob_col"].blob.image_normalize( |
| 217 | + alpha=50.0, beta=150.0, norm_type="minmax", dst=series, connection=bq_connection |
| 218 | + ) |
| 219 | + expected_df = pd.DataFrame( |
| 220 | + { |
| 221 | + "uri": images_output_uris, |
| 222 | + "version": [None, None], |
| 223 | + "authorizer": [bq_connection.casefold(), bq_connection.casefold()], |
| 224 | + "details": [None, None], |
| 225 | + } |
| 226 | + ) |
| 227 | + pd.testing.assert_frame_equal( |
| 228 | + actual.struct.explode().to_pandas(), |
| 229 | + expected_df, |
| 230 | + check_dtype=False, |
| 231 | + check_index_type=False, |
| 232 | + ) |
| 233 | + |
| 234 | + # verify the files exist |
| 235 | + assert not actual.blob.size().isna().any() |
| 236 | + |
| 237 | + |
| 238 | +def test_blob_image_normalize_to_folder( |
| 239 | + images_mm_df: bpd.DataFrame, |
| 240 | + bq_connection: str, |
| 241 | + images_output_folder: str, |
| 242 | + images_output_uris: list[str], |
| 243 | +): |
| 244 | + bigframes.options.experiments.blob = True |
| 245 | + |
| 246 | + actual = images_mm_df["blob_col"].blob.image_normalize( |
| 247 | + alpha=50.0, |
| 248 | + beta=150.0, |
| 249 | + norm_type="minmax", |
| 250 | + dst=images_output_folder, |
| 251 | + connection=bq_connection, |
| 252 | + ) |
| 253 | + expected_df = pd.DataFrame( |
| 254 | + { |
| 255 | + "uri": images_output_uris, |
| 256 | + "version": [None, None], |
| 257 | + "authorizer": [bq_connection.casefold(), bq_connection.casefold()], |
| 258 | + "details": [None, None], |
| 259 | + } |
| 260 | + ) |
| 261 | + pd.testing.assert_frame_equal( |
| 262 | + actual.struct.explode().to_pandas(), |
| 263 | + expected_df, |
| 264 | + check_dtype=False, |
| 265 | + check_index_type=False, |
| 266 | + ) |
| 267 | + |
| 268 | + # verify the files exist |
| 269 | + assert not actual.blob.size().isna().any() |
| 270 | + |
| 271 | + |
| 272 | +def test_blob_image_normalize_to_bq(images_mm_df: bpd.DataFrame, bq_connection: str): |
| 273 | + bigframes.options.experiments.blob = True |
| 274 | + |
| 275 | + actual = images_mm_df["blob_col"].blob.image_normalize( |
| 276 | + alpha=50.0, beta=150.0, norm_type="minmax", connection=bq_connection |
| 277 | + ) |
| 278 | + |
| 279 | + assert isinstance(actual, bpd.Series) |
| 280 | + assert len(actual) == 2 |
| 281 | + assert actual.dtype == dtypes.BYTES_DTYPE |
0 commit comments