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
11 changes: 10 additions & 1 deletion bigframes/session/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1050,7 +1050,12 @@ def _read_pandas(
inline_df = self._read_pandas_inline(pandas_dataframe)
if inline_df is not None:
return inline_df
return self._read_pandas_load_job(pandas_dataframe, api_name)
try:
return self._read_pandas_load_job(pandas_dataframe, api_name)
except pa.ArrowInvalid as e:
raise pa.ArrowInvalid(
f"Could not convert with a BigQuery type: `{e}`. "
) from e

def _read_pandas_inline(
self, pandas_dataframe: pandas.DataFrame
Expand All @@ -1064,6 +1069,10 @@ def _read_pandas_inline(
inline_df = dataframe.DataFrame(
blocks.Block.from_local(pandas_dataframe, self)
)
except pa.ArrowInvalid as e:
raise pa.ArrowInvalid(
f"Could not convert with a BigQuery type: `{e}`. "
) from e
except ValueError: # Thrown by ibis for some unhandled types
return None
except pa.ArrowTypeError: # Thrown by arrow for types without mapping (geo).
Expand Down
6 changes: 6 additions & 0 deletions tests/system/small/test_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import google.cloud.bigquery as bigquery
import numpy as np
import pandas as pd
import pyarrow as pa
import pytest

import bigframes
Expand Down Expand Up @@ -436,6 +437,11 @@ def test_read_pandas_index(session):
pd.testing.assert_index_equal(bf_idx.to_pandas(), pd_idx)


def test_read_pandas_w_unsupported_mixed_dtype(session):
with pytest.raises(pa.ArrowInvalid, match="Could not convert"):
session.read_pandas(pd.DataFrame({"a": [1, "hello"]}))


def test_read_pandas_inline_respects_location():
options = bigframes.BigQueryOptions(location="europe-west1")
session = bigframes.Session(options)
Expand Down