Reputation: 1
I have a bigquery dataframe which has a timestamp column as shown below. I want to create a new column by adding 7 days to the creation_ts column.
I have tried it as follows
`**df["TEMP_LABEL_END_TS"] = df["creation_ts"] + timedelta(days=7)**`
I am getting the following error message .
ValueError: Literal did not coerce to a supported data type: interval('D').
Can anyone help me with this.
Upvotes: 0
Views: 72
Reputation: 14786
Pandas-like timedelta behavior is not yet supported. I have filed a feature request on your behalf at https://github.com/googleapis/python-bigquery-dataframes/issues/719 and assigned it to a BigQuery DataFrames (bigframes) teammate who has most recently worked on datetime support.
In the meantime, you can workaround by casting to INT64 and back.
import bigframes.pandas as bpd
bpd.options.bigquery.project = "swast-scratch"
df = bpd.read_gbq_table("my-proj.my_dataset.my_table")
bpd.to_datetime(
df['timestamp_col'].astype('Int64') + (7 * 24 * 60 * 60 * 1_000_000),
utc=True,
unit="us",
)
Upvotes: 0