Skip to content

Commit 77c8898

Browse files
authored
chore: add experimental blob.image_blur() dst as folder (#1279)
* chore: add experimental blob.image_blur() dst as folder * fix
1 parent 3dcae2d commit 77c8898

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

bigframes/operations/blob.py

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,14 @@
1414

1515
from __future__ import annotations
1616

17-
from typing import Optional
17+
import os
18+
from typing import cast, Optional, Union
1819

1920
import IPython.display as ipy_display
2021
import requests
2122

2223
from bigframes import clients
24+
import bigframes.dataframe
2325
from bigframes.operations import base
2426
import bigframes.operations as ops
2527
import bigframes.series
@@ -74,7 +76,7 @@ def image_blur(
7476
self,
7577
ksize: tuple[int, int],
7678
*,
77-
dst: bigframes.series.Series,
79+
dst: Union[str, bigframes.series.Series],
7880
connection: Optional[str] = None,
7981
) -> bigframes.series.Series:
8082
"""Blurs images.
@@ -84,11 +86,11 @@ def image_blur(
8486
8587
Args:
8688
ksize (tuple(int, int)): Kernel size.
87-
dst (bigframes.series.Series): Destination blob series.
88-
connection (str or None, default None): BQ connection used for internet transactions. If None, uses default connection of the session.
89+
dst (str or bigframes.series.Series): Destination GCS folder str or blob series.
90+
connection (str or None, default None): BQ connection used for function internet transactions, and the output blob if "dst" is str. If None, uses default connection of the session.
8991
9092
Returns:
91-
JSON: Runtime info of the Blob.
93+
BigFrames Blob Series
9294
"""
9395
import bigframes.blob._functions as blob_func
9496

@@ -99,6 +101,15 @@ def image_blur(
99101
default_location=self._block.session._location,
100102
)
101103

104+
if isinstance(dst, str):
105+
dst = os.path.join(dst, "")
106+
src_uri = bigframes.series.Series(self._block).struct.explode()["uri"]
107+
# Replace src folder with dst folder, keep the file names.
108+
dst_uri = src_uri.str.replace(r"^.*\/(.*)$", rf"{dst}\1", regex=True)
109+
dst = cast(
110+
bigframes.series.Series, dst_uri.str.to_blob(connection=connection)
111+
)
112+
102113
image_blur_udf = blob_func.TransformFunction(
103114
blob_func.image_blur_def,
104115
session=self._block.session,
@@ -116,4 +127,7 @@ def image_blur(
116127
df = src_rt.to_frame().join(dst_rt.to_frame(), how="outer")
117128
df["ksize_x"], df["ksize_y"] = ksize
118129

119-
return df.apply(image_blur_udf, axis=1)
130+
res = df.apply(image_blur_udf, axis=1)
131+
res.cache() # to execute the udf
132+
133+
return dst

0 commit comments

Comments
 (0)