Skip to content

Commit

Permalink
fix: throw exception for data type mismatch for load_table_from_dataf…
Browse files Browse the repository at this point in the history
…rame api
  • Loading branch information
Gaurang033 committed Feb 21, 2024
1 parent 2542bd3 commit a2285b6
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions google/cloud/bigquery/_pandas_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,11 +302,15 @@ def bq_to_arrow_array(series, bq_field):

field_type_upper = bq_field.field_type.upper() if bq_field.field_type else ""

if bq_field.mode.upper() == "REPEATED":
return pyarrow.ListArray.from_pandas(series, type=arrow_type)
if field_type_upper in schema._STRUCT_TYPES:
return pyarrow.StructArray.from_pandas(series, type=arrow_type)
return pyarrow.Array.from_pandas(series, type=arrow_type)
try:
if bq_field.mode.upper() == "REPEATED":
return pyarrow.ListArray.from_pandas(series, type=arrow_type)
if field_type_upper in schema._STRUCT_TYPES:
return pyarrow.StructArray.from_pandas(series, type=arrow_type)

return pyarrow.Array.from_pandas(series, type=arrow_type)
except pyarrow.lib.ArrowInvalid as ae:
raise ValueError(f"{str(ae)} for column {bq_field.name}")


def get_column_or_index(dataframe, name):
Expand Down

0 comments on commit a2285b6

Please sign in to comment.