Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions bigframes/operations/blob.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,9 +228,14 @@ def display(
df._set_internal_query_job(query_job)

def display_single_url(
read_url: str, content_type: Union[str, pd._libs.missing.NAType]
read_url: Union[str, pd._libs.missing.NAType],
content_type: Union[str, pd._libs.missing.NAType],
):
if content_type is pd.NA: # display as raw data or error
if pd.isna(read_url):
ipy_display.display("<NA>")
return

if pd.isna(content_type): # display as raw data or error
response = requests.get(read_url)
ipy_display.display(response.content)
return
Expand Down
5 changes: 5 additions & 0 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,11 @@
# Sessions are executed in the order so putting the smaller sessions
# ahead to fail fast at presubmit running.
nox.options.sessions = [
# Include unit_noextras to ensure at least some unit tests contribute to
# coverage.
# TODO(tswast): Consider removing this when unit_noextras and cover is run
# from GitHub actions.
"unit_noextras",
"system-3.9", # No extras.
"system-3.11",
"cover",
Expand Down
33 changes: 33 additions & 0 deletions tests/system/small/blob/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from unittest import mock

import IPython.display
import pandas as pd

import bigframes
Expand Down Expand Up @@ -92,3 +95,33 @@ def test_blob_create_read_gbq_object_table(
pd.testing.assert_frame_equal(
pd_blob_df, expected_df, check_dtype=False, check_index_type=False
)


def test_display_images(monkeypatch, images_mm_df: bpd.DataFrame):
mock_display = mock.Mock()
monkeypatch.setattr(IPython.display, "display", mock_display)

images_mm_df["blob_col"].blob.display()

for call in mock_display.call_args_list:
args, _ = call
arg = args[0]
assert isinstance(arg, IPython.display.Image)


def test_display_nulls(
monkeypatch,
bq_connection: str,
session: bigframes.Session,
):
uri_series = bpd.Series([None, None, None], dtype="string", session=session)
blob_series = uri_series.str.to_blob(connection=bq_connection)
mock_display = mock.Mock()
monkeypatch.setattr(IPython.display, "display", mock_display)

blob_series.blob.display()

for call in mock_display.call_args_list:
args, _ = call
arg = args[0]
assert arg == "<NA>"