@@ -794,13 +794,14 @@ def _read_pandas(
794
794
)
795
795
796
796
if write_engine == "default" :
797
- inline_df = self . _read_pandas_inline ( pandas_dataframe , should_raise = False )
798
- if inline_df is not None :
797
+ try :
798
+ inline_df = self . _read_pandas_inline ( pandas_dataframe )
799
799
return inline_df
800
+ except ValueError :
801
+ pass
800
802
return self ._read_pandas_load_job (pandas_dataframe , api_name )
801
803
elif write_engine == "bigquery_inline" :
802
- # Regarding the type: ignore, with should_raise=True, this should never return None.
803
- return self ._read_pandas_inline (pandas_dataframe , should_raise = True ) # type: ignore
804
+ return self ._read_pandas_inline (pandas_dataframe )
804
805
elif write_engine == "bigquery_load" :
805
806
return self ._read_pandas_load_job (pandas_dataframe , api_name )
806
807
elif write_engine == "bigquery_streaming" :
@@ -809,12 +810,16 @@ def _read_pandas(
809
810
raise ValueError (f"Got unexpected write_engine '{ write_engine } '" )
810
811
811
812
def _read_pandas_inline (
812
- self , pandas_dataframe : pandas .DataFrame , should_raise = False
813
- ) -> Optional [ dataframe .DataFrame ] :
813
+ self , pandas_dataframe : pandas .DataFrame
814
+ ) -> dataframe .DataFrame :
814
815
import bigframes .dataframe as dataframe
815
816
816
- if pandas_dataframe .memory_usage (deep = True ).sum () > MAX_INLINE_DF_BYTES :
817
- return None
817
+ memory_usage = pandas_dataframe .memory_usage (deep = True ).sum ()
818
+ if memory_usage > MAX_INLINE_DF_BYTES :
819
+ raise ValueError (
820
+ f"DataFrame size ({ memory_usage } bytes) exceeds the maximum allowed "
821
+ f"for inline data ({ MAX_INLINE_DF_BYTES } bytes)."
822
+ )
818
823
819
824
try :
820
825
local_block = blocks .Block .from_local (pandas_dataframe , self )
@@ -825,29 +830,22 @@ def _read_pandas_inline(
825
830
ValueError , # Thrown by ibis for some unhandled types
826
831
TypeError , # Not all types handleable by local code path
827
832
) as exc :
828
- if should_raise :
829
- raise ValueError (
830
- f"Could not convert with a BigQuery type: `{ exc } `. "
831
- ) from exc
832
- else :
833
- return None
834
-
835
- inline_types = inline_df ._block .expr .schema .dtypes
833
+ raise ValueError (
834
+ f"Could not convert with a BigQuery type: `{ exc } `. "
835
+ ) from exc
836
836
837
837
# Make sure all types are inlinable to avoid escaping errors.
838
+ inline_types = inline_df ._block .expr .schema .dtypes
838
839
noninlinable_types = [
839
840
dtype for dtype in inline_types if dtype not in INLINABLE_DTYPES
840
841
]
841
- if len (noninlinable_types ) == 0 :
842
- return inline_df
843
-
844
- if should_raise :
842
+ if len (noninlinable_types ) != 0 :
845
843
raise ValueError (
846
844
f"Could not inline with a BigQuery type: `{ noninlinable_types } `. "
847
845
f"{ constants .FEEDBACK_LINK } "
848
846
)
849
- else :
850
- return None
847
+
848
+ return inline_df
851
849
852
850
def _read_pandas_load_job (
853
851
self ,
0 commit comments