Skip to content

Commit 01dfe83

Browse files
authored
chore: fix experimental blob errors in preview non-exist files (#1479)
1 parent 9e471fb commit 01dfe83

File tree

2 files changed

+19
-11
lines changed

2 files changed

+19
-11
lines changed

bigframes/dataframe.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -778,15 +778,15 @@ def _repr_html_(self) -> str:
778778

779779
def obj_ref_rt_to_html(obj_ref_rt) -> str:
780780
obj_ref_rt_json = json.loads(obj_ref_rt)
781-
gcs_metadata = obj_ref_rt_json["objectref"]["details"][
782-
"gcs_metadata"
783-
]
784-
content_type = typing.cast(
785-
str, gcs_metadata.get("content_type", "")
786-
)
787-
if content_type.startswith("image"):
788-
url = obj_ref_rt_json["access_urls"]["read_url"]
789-
return f'<img src="{url}">'
781+
obj_ref_details = obj_ref_rt_json["objectref"]["details"]
782+
if "gcs_metadata" in obj_ref_details:
783+
gcs_metadata = obj_ref_details["gcs_metadata"]
784+
content_type = typing.cast(
785+
str, gcs_metadata.get("content_type", "")
786+
)
787+
if content_type.startswith("image"):
788+
url = obj_ref_rt_json["access_urls"]["read_url"]
789+
return f'<img src="{url}">'
790790

791791
return f'uri: {obj_ref_rt_json["objectref"]["uri"]}, authorizer: {obj_ref_rt_json["objectref"]["authorizer"]}'
792792

bigframes/operations/blob.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from typing import cast, Optional, Union
1919

2020
import IPython.display as ipy_display
21+
import pandas as pd
2122
import requests
2223

2324
from bigframes import clients
@@ -209,8 +210,15 @@ def display(self, n: int = 3, *, content_type: str = ""):
209210
else:
210211
df["content_type"] = df["blob_col"].blob.content_type()
211212

212-
def display_single_url(read_url: str, content_type: str):
213-
content_type = content_type.casefold()
213+
def display_single_url(
214+
read_url: str, content_type: Union[str, pd._libs.missing.NAType]
215+
):
216+
if content_type is pd.NA: # display as raw data or error
217+
response = requests.get(read_url)
218+
ipy_display.display(response.content)
219+
return
220+
221+
content_type = cast(str, content_type).casefold()
214222

215223
if content_type.startswith("image"):
216224
ipy_display.display(ipy_display.Image(url=read_url))

0 commit comments

Comments
 (0)