File tree Expand file tree Collapse file tree 2 files changed +16
-1
lines changed Expand file tree Collapse file tree 2 files changed +16
-1
lines changed Original file line number Diff line number Diff line change @@ -1050,7 +1050,12 @@ def _read_pandas(
10501050 inline_df = self ._read_pandas_inline (pandas_dataframe )
10511051 if inline_df is not None :
10521052 return inline_df
1053- return self ._read_pandas_load_job (pandas_dataframe , api_name )
1053+ try :
1054+ return self ._read_pandas_load_job (pandas_dataframe , api_name )
1055+ except pa .ArrowInvalid as e :
1056+ raise pa .ArrowInvalid (
1057+ f"Could not convert with a BigQuery type: `{ e } `. "
1058+ ) from e
10541059
10551060 def _read_pandas_inline (
10561061 self , pandas_dataframe : pandas .DataFrame
@@ -1064,6 +1069,10 @@ def _read_pandas_inline(
10641069 inline_df = dataframe .DataFrame (
10651070 blocks .Block .from_local (pandas_dataframe , self )
10661071 )
1072+ except pa .ArrowInvalid as e :
1073+ raise pa .ArrowInvalid (
1074+ f"Could not convert with a BigQuery type: `{ e } `. "
1075+ ) from e
10671076 except ValueError : # Thrown by ibis for some unhandled types
10681077 return None
10691078 except pa .ArrowTypeError : # Thrown by arrow for types without mapping (geo).
Original file line number Diff line number Diff line change 2424import google .cloud .bigquery as bigquery
2525import numpy as np
2626import pandas as pd
27+ import pyarrow as pa
2728import pytest
2829
2930import bigframes
@@ -436,6 +437,11 @@ def test_read_pandas_index(session):
436437 pd .testing .assert_index_equal (bf_idx .to_pandas (), pd_idx )
437438
438439
440+ def test_read_pandas_w_unsupported_mixed_dtype (session ):
441+ with pytest .raises (pa .ArrowInvalid , match = "Could not convert" ):
442+ session .read_pandas (pd .DataFrame ({"a" : [1 , "hello" ]}))
443+
444+
439445def test_read_pandas_inline_respects_location ():
440446 options = bigframes .BigQueryOptions (location = "europe-west1" )
441447 session = bigframes .Session (options )
You can’t perform that action at this time.
0 commit comments