@@ -794,13 +794,12 @@ def _read_pandas(
794
794
)
795
795
796
796
if write_engine == "default" :
797
- try :
798
- inline_df = self ._read_pandas_inline (pandas_dataframe )
799
- return inline_df
800
- except ValueError :
801
- pass
802
- return self ._read_pandas_load_job (pandas_dataframe , api_name )
803
- elif write_engine == "bigquery_inline" :
797
+ is_df_large = (
798
+ pandas_dataframe .memory_usage (deep = True ).sum () > MAX_INLINE_DF_BYTES
799
+ )
800
+ write_engine = "bigquery_load" if is_df_large else "bigquery_inline"
801
+
802
+ if write_engine == "bigquery_inline" :
804
803
return self ._read_pandas_inline (pandas_dataframe )
805
804
elif write_engine == "bigquery_load" :
806
805
return self ._read_pandas_load_job (pandas_dataframe , api_name )
@@ -814,37 +813,8 @@ def _read_pandas_inline(
814
813
) -> dataframe .DataFrame :
815
814
import bigframes .dataframe as dataframe
816
815
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
- )
823
-
824
- try :
825
- local_block = blocks .Block .from_local (pandas_dataframe , self )
826
- inline_df = dataframe .DataFrame (local_block )
827
- except (
828
- pa .ArrowInvalid , # Thrown by arrow for unsupported types, such as geo.
829
- pa .ArrowTypeError , # Thrown by arrow for types without mapping (geo).
830
- ValueError , # Thrown by ibis for some unhandled types
831
- TypeError , # Not all types handleable by local code path
832
- ) as exc :
833
- raise ValueError (
834
- f"Could not convert with a BigQuery type: `{ exc } `. "
835
- ) from exc
836
-
837
- # Make sure all types are inlinable to avoid escaping errors.
838
- inline_types = inline_df ._block .expr .schema .dtypes
839
- noninlinable_types = [
840
- dtype for dtype in inline_types if dtype not in INLINABLE_DTYPES
841
- ]
842
- if len (noninlinable_types ) != 0 :
843
- raise ValueError (
844
- f"Could not inline with a BigQuery type: `{ noninlinable_types } `. "
845
- f"{ constants .FEEDBACK_LINK } "
846
- )
847
-
816
+ local_block = blocks .Block .from_local (pandas_dataframe , self )
817
+ inline_df = dataframe .DataFrame (local_block )
848
818
return inline_df
849
819
850
820
def _read_pandas_load_job (
0 commit comments