Skip to content

Commit baefadf

Browse files
authored
chore: blob.display to support width and height params (#1628)
* chore: blob.display to support width and height params * wording
1 parent 881e4f0 commit baefadf

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

bigframes/operations/blob.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,14 @@ def write_url(self) -> bigframes.series.Series:
225225
ops.JSONValue(json_path="$.access_urls.write_url")
226226
)
227227

228-
def display(self, n: int = 3, *, content_type: str = ""):
228+
def display(
229+
self,
230+
n: int = 3,
231+
*,
232+
content_type: str = "",
233+
width: Optional[int] = None,
234+
height: Optional[int] = None,
235+
):
229236
"""Display the blob content in the IPython Notebook environment. Only works for image type now.
230237
231238
.. note::
@@ -234,6 +241,8 @@ def display(self, n: int = 3, *, content_type: str = ""):
234241
Args:
235242
n (int, default 3): number of sample blob objects to display.
236243
content_type (str, default ""): content type of the blob. If unset, use the blob metadata of the storage. Possible values are "image", "audio" and "video".
244+
width (int or None, default None): width in pixels that the image/video are constrained to. If unset, use the image/video's original size or ratio. No-op for other content types.
245+
height (int or None, default None): height in pixels that the image/video are constrained to. If unset, use the image/video's original size or ratio. No-op for other content types.
237246
"""
238247
# col name doesn't matter here. Rename to avoid column name conflicts
239248
df = bigframes.series.Series(self._block).rename("blob_col").to_frame()
@@ -259,13 +268,17 @@ def display_single_url(
259268
content_type = cast(str, content_type).casefold()
260269

261270
if content_type.startswith("image"):
262-
ipy_display.display(ipy_display.Image(url=read_url))
271+
ipy_display.display(
272+
ipy_display.Image(url=read_url, width=width, height=height)
273+
)
263274
elif content_type.startswith("audio"):
264275
# using url somehow doesn't work with audios
265276
response = requests.get(read_url)
266277
ipy_display.display(ipy_display.Audio(response.content))
267278
elif content_type.startswith("video"):
268-
ipy_display.display(ipy_display.Video(read_url))
279+
ipy_display.display(
280+
ipy_display.Video(read_url, width=width, height=height)
281+
)
269282
else: # display as raw data
270283
response = requests.get(read_url)
271284
ipy_display.display(response.content)

0 commit comments

Comments
 (0)