Thanks to visit codestin.com
Credit goes to github.com

Skip to content

chore: add code samples for Data Manipulation public doc #1722

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
May 12, 2025
29 changes: 29 additions & 0 deletions samples/snippets/bigquery_modules_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,19 @@


def test_bigquery_dataframes_examples() -> None:
# [START bigquery_dataframes_bigquery_methods_array_agg]
import bigframes.bigquery as bbq
import bigframes.pandas as bpd

s = bpd.Series([0, 1, 2, 3, 4, 5])

# Group values by whether they are divisble by 2 and aggregate them into arrays
bbq.array_agg(s.groupby(s % 2 == 0))
# False [1 3 5]
# True [0 2 4]
# dtype: list<item: int64>[pyarrow]
# [END bigquery_dataframes_bigquery_methods_array_agg]

# [START bigquery_dataframes_bigquery_methods_struct]
import bigframes.bigquery as bbq
import bigframes.pandas as bpd
Expand All @@ -36,6 +49,22 @@ def test_bigquery_dataframes_examples() -> None:
# dtype: struct[pyarrow]
# [END bigquery_dataframes_bigquery_methods_struct]

# [START bigquery_dataframes_bigquery_methods_unix_micros]
import pandas as pd

import bigframes.bigquery as bbq
import bigframes.pandas as bpd

# Create a series that consists of three timestamps: [1970-01-01, 1970-01-02, 1970-01-03]
s = bpd.Series(pd.date_range("1970-01-01", periods=3, freq="d", tz="UTC"))

bbq.unix_micros(s)
# 0 0
# 1 86400000000
# 2 172800000000
# dtype: Int64
# [END bigquery_dataframes_bigquery_methods_unix_micros]

# [START bigquery_dataframes_bigquery_methods_scalar]
import bigframes.bigquery as bbq
import bigframes.pandas as bpd
Expand Down