Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@

def _serialize_value_for_sql(value):
"""Serializes a Python value from a pandas DataFrame into a BigQuery SQL literal."""
if isinstance(value, (list, np.ndarray)):
# Format arrays.
return f"[{', '.join(_serialize_value_for_sql(v) for v in value)}]"
if pd.isna(value):
return "NULL"
if isinstance(value, str):
Expand All @@ -52,9 +55,6 @@ def _serialize_value_for_sql(value):
if isinstance(value, (datetime.datetime, datetime.date, pd.Timestamp)):
# Timestamps and datetimes need to be quoted.
return f"'{value}'"
if isinstance(value, (list, np.ndarray)):
# Format arrays.
return f"[{', '.join(_serialize_value_for_sql(v) for v in value)}]"
if isinstance(value, dict):
# For STRUCT, BQ expects ('val1', 'val2', ...).
# The values() order from the dataframe should match the column order.
Expand Down