Skip to content
This repository was archived by the owner on Apr 1, 2026. It is now read-only.

Commit 1a1fc23

Browse files
committed
Merge branch 'main' into shuowei-fix-compiler-syntax-guards
2 parents 153de04 + 0ebc733 commit 1a1fc23

File tree

46 files changed

+785
-1233
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+785
-1233
lines changed

.librarian/state.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
image: us-central1-docker.pkg.dev/cloud-sdk-librarian-prod/images-prod/python-librarian-generator@sha256:160860d189ff1c2f7515638478823712fa5b243e27ccc33a2728669fa1e2ed0c
22
libraries:
33
- id: bigframes
4-
version: 2.37.0
4+
version: 2.38.0
55
last_generated_commit: ""
66
apis: []
77
source_roots:

CHANGELOG.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,29 @@
44

55
[1]: https://pypi.org/project/bigframes/#history
66

7+
## [2.38.0](https://github.com/googleapis/python-bigquery-dataframes/compare/v2.37.0...v2.38.0) (2026-03-16)
8+
9+
10+
### Documentation
11+
12+
* add notebooks to user guide page (#2505) ([5cf37888bc0b4b1b0993dadd1e0fe5ee08341ef4](https://github.com/googleapis/python-bigquery-dataframes/commit/5cf37888bc0b4b1b0993dadd1e0fe5ee08341ef4))
13+
* Fix typo in ExperimentOptions class docstring (#2498) ([077cb2ebe515fc5e07bcbb5dc663edd28d3eaf00](https://github.com/googleapis/python-bigquery-dataframes/commit/077cb2ebe515fc5e07bcbb5dc663edd28d3eaf00))
14+
15+
16+
### Features
17+
18+
* add `df.bigquery` pandas accessor (#2513) ([91b6c245521218bb78b543885e1b9424278ce2ab](https://github.com/googleapis/python-bigquery-dataframes/commit/91b6c245521218bb78b543885e1b9424278ce2ab))
19+
* use EUC for AI IF, CLASSIFY, and SCORE when connection is not provided (#2507) ([fe94910abff28e244dd79e1540a6c2184a12eb44](https://github.com/googleapis/python-bigquery-dataframes/commit/fe94910abff28e244dd79e1540a6c2184a12eb44))
20+
* Add `bigframes.bigquery.rand()` function (#2501) ([5c43efb745118f506ecc30196da68e9d6f4346dc](https://github.com/googleapis/python-bigquery-dataframes/commit/5c43efb745118f506ecc30196da68e9d6f4346dc))
21+
* add bigquery.ml.get_insights function (#2493) ([d29a60953ac989bb2c95e6eec3010620ac776a3c](https://github.com/googleapis/python-bigquery-dataframes/commit/d29a60953ac989bb2c95e6eec3010620ac776a3c))
22+
* Add str, dt accessors to pd.col Expression objects (#2488) ([ce5de57019449ca77d308946df72f04289343b51](https://github.com/googleapis/python-bigquery-dataframes/commit/ce5de57019449ca77d308946df72f04289343b51))
23+
24+
25+
### Bug Fixes
26+
27+
* handle unsupported types and empty results in describe (#2506) ([2326ad6aec15c20a66756eff093b50be484b3ba8](https://github.com/googleapis/python-bigquery-dataframes/commit/2326ad6aec15c20a66756eff093b50be484b3ba8))
28+
* no longer automatically use anywidget in the `%%bqsql` magics (#2504) ([43353e2bc9ffbc38b7383c24ecaac80d3b8bab32](https://github.com/googleapis/python-bigquery-dataframes/commit/43353e2bc9ffbc38b7383c24ecaac80d3b8bab32))
29+
730
## [2.37.0](https://github.com/googleapis/python-bigquery-dataframes/compare/v2.36.0...v2.37.0) (2026-03-03)
831

932

bigframes/bigquery/__init__.py

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,38 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
"""This module integrates BigQuery built-in functions for use with DataFrame objects,
16-
such as array functions:
17-
https://cloud.google.com/bigquery/docs/reference/standard-sql/array_functions. """
15+
"""
16+
Access BigQuery-specific operations and namespaces within BigQuery DataFrames.
17+
18+
This module provides specialized functions and sub-modules that expose BigQuery's
19+
advanced capabilities to DataFrames and Series. It acts as a bridge between the
20+
pandas-compatible API and the full power of BigQuery SQL.
21+
22+
Key sub-modules include:
23+
24+
* :mod:`bigframes.bigquery.ai`: Generative and predictive AI functions (Gemini, BQML).
25+
* :mod:`bigframes.bigquery.ml`: Direct access to BigQuery ML model operations.
26+
* :mod:`bigframes.bigquery.obj`: Support for BigQuery object tables.
27+
28+
This module also provides direct access to optimized BigQuery functions for:
29+
30+
* **JSON Processing:** High-performance functions like ``json_extract``, ``json_value``,
31+
and ``parse_json`` for handling semi-structured data.
32+
* **Geospatial Analysis:** Comprehensive geographic functions such as ``st_area``,
33+
``st_distance``, and ``st_centroid`` (``ST_`` prefixed functions).
34+
* **Array Operations:** Tools for working with BigQuery arrays, including ``array_agg``
35+
and ``array_length``.
36+
* **Vector Search:** Integration with BigQuery's vector search and indexing
37+
capabilities for high-dimensional data.
38+
* **Custom SQL:** The ``sql_scalar`` function allows embedding raw SQL snippets for
39+
advanced operations not yet directly mapped in the API.
40+
41+
By using these functions, you can leverage BigQuery's high-performance engine for
42+
domain-specific tasks while maintaining a Python-centric development experience.
43+
44+
For the full list of BigQuery standard SQL functions, see:
45+
https://cloud.google.com/bigquery/docs/reference/standard-sql/functions-reference
46+
"""
1847

1948
import sys
2049

bigframes/bigquery/_operations/ai.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -880,6 +880,7 @@ def forecast(
880880
id_cols: Iterable[str] | None = None,
881881
horizon: int = 10,
882882
confidence_level: float = 0.95,
883+
output_historical_time_series: bool = False,
883884
context_window: int | None = None,
884885
) -> dataframe.DataFrame:
885886
"""
@@ -914,6 +915,15 @@ def forecast(
914915
confidence_level (float, default 0.95):
915916
A FLOAT64 value that specifies the percentage of the future values that fall in the prediction interval.
916917
The default value is 0.95. The valid input range is [0, 1).
918+
output_historical_time_series (bool, default False):
919+
A BOOL value that determines whether the input data is returned
920+
along with the forecasted data. Set this argument to TRUE to return
921+
input data. The default value is FALSE.
922+
923+
Returning the input data along with the forecasted data lets you
924+
compare the historical value of the data column with the forecasted
925+
value of the data column, or chart the change in the data column
926+
values over time.
917927
context_window (int, optional):
918928
An int value that specifies the context window length used by BigQuery ML's built-in TimesFM model.
919929
The context window length determines how many of the most recent data points from the input time series are use by the model.
@@ -945,6 +955,7 @@ def forecast(
945955
"timestamp_col": timestamp_col,
946956
"model": model,
947957
"horizon": horizon,
958+
"output_historical_time_series": output_historical_time_series,
948959
"confidence_level": confidence_level,
949960
}
950961
if id_cols:

bigframes/bigquery/_operations/io.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
import pandas as pd
2020

2121
from bigframes.bigquery._operations.table import _get_table_metadata
22+
import bigframes.core.compile.sqlglot.sql as sql
2223
import bigframes.core.logging.log_adapter as log_adapter
23-
import bigframes.core.sql.io
2424
import bigframes.session
2525

2626

@@ -73,7 +73,7 @@ def load_data(
7373
"""
7474
import bigframes.pandas as bpd
7575

76-
sql = bigframes.core.sql.io.load_data_ddl(
76+
load_data_expr = sql.load_data(
7777
table_name=table_name,
7878
write_disposition=write_disposition,
7979
columns=columns,
@@ -84,11 +84,12 @@ def load_data(
8484
with_partition_columns=with_partition_columns,
8585
connection_name=connection_name,
8686
)
87+
sql_text = sql.to_sql(load_data_expr)
8788

8889
if session is None:
89-
bpd.read_gbq_query(sql)
90+
bpd.read_gbq_query(sql_text)
9091
session = bpd.get_global_session()
9192
else:
92-
session.read_gbq_query(sql)
93+
session.read_gbq_query(sql_text)
9394

9495
return _get_table_metadata(bqclient=session.bqclient, table_name=table_name)

bigframes/bigquery/_operations/table.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
import google.cloud.bigquery
2020
import pandas as pd
2121

22+
import bigframes.core.compile.sqlglot.sql as sg_sql
2223
import bigframes.core.logging.log_adapter as log_adapter
23-
import bigframes.core.sql.table
2424
import bigframes.session
2525

2626

@@ -80,14 +80,16 @@ def create_external_table(
8080
"""
8181
import bigframes.pandas as bpd
8282

83-
sql = bigframes.core.sql.table.create_external_table_ddl(
84-
table_name=table_name,
85-
replace=replace,
86-
if_not_exists=if_not_exists,
87-
columns=columns,
88-
partition_columns=partition_columns,
89-
connection_name=connection_name,
90-
options=options,
83+
sql = sg_sql.to_sql(
84+
sg_sql.create_external_table(
85+
table_name=table_name,
86+
replace=replace,
87+
if_not_exists=if_not_exists,
88+
columns=columns,
89+
partition_columns=partition_columns,
90+
connection_name=connection_name,
91+
options=options,
92+
)
9193
)
9294

9395
if session is None:

bigframes/bigquery/ai.py

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,49 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
"""This module integrates BigQuery built-in AI functions for use with Series/DataFrame objects,
16-
such as AI.GENERATE_BOOL:
17-
https://cloud.google.com/bigquery/docs/reference/standard-sql/bigqueryml-syntax-ai-generate-bool"""
15+
"""
16+
Integrate BigQuery built-in AI functions into your BigQuery DataFrames workflow.
17+
18+
The ``bigframes.bigquery.ai`` module provides a Pythonic interface to leverage BigQuery ML's
19+
generative AI and predictive functions directly on BigQuery DataFrames and Series objects.
20+
These functions enable you to perform advanced AI tasks at scale without moving data
21+
out of BigQuery.
22+
23+
Key capabilities include:
24+
25+
* **Generative AI:** Use :func:`bigframes.bigquery.ai.generate` (Gemini) to
26+
perform text analysis, translation, or
27+
content generation. Specialized versions like
28+
:func:`~bigframes.bigquery.ai.generate_bool`,
29+
:func:`~bigframes.bigquery.ai.generate_int`, and
30+
:func:`~bigframes.bigquery.ai.generate_double` are available for structured
31+
outputs.
32+
* **Embeddings:** Generate vector embeddings for text using
33+
:func:`~bigframes.bigquery.ai.generate_embedding`, which are essential for
34+
semantic search and retrieval-augmented generation (RAG) workflows.
35+
* **Classification and Scoring:** Apply machine learning models to your data for
36+
predictive tasks with :func:`~bigframes.bigquery.ai.classify` and
37+
:func:`~bigframes.bigquery.ai.score`.
38+
* **Forecasting:** Predict future values in time-series data using
39+
:func:`~bigframes.bigquery.ai.forecast`.
40+
41+
**Example usage:**
42+
43+
>>> import bigframes.pandas as bpd
44+
>>> import bigframes.bigquery as bbq
45+
46+
>>> df = bpd.DataFrame({
47+
... "text_input": [
48+
... "Is this a positive review? The food was terrible.",
49+
... ],
50+
... }) # doctest: +SKIP
51+
52+
>>> # Assuming a Gemini model has been created in BigQuery as 'my_gemini_model'
53+
>>> result = bq.ai.generate_text("my_gemini_model", df["text_input"]) # doctest: +SKIP
54+
55+
For more information on the underlying BigQuery ML syntax, see:
56+
https://cloud.google.com/bigquery/docs/reference/standard-sql/bigqueryml-syntax-ai-generate-bool
57+
"""
1858

1959
from bigframes.bigquery._operations.ai import (
2060
classify,

bigframes/core/compile/sqlglot/expressions/datetime_ops.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,12 @@ def _(expr: TypedExpr, op: ops.ToDatetimeOp) -> sge.Expression:
371371
)
372372
return sge.Cast(this=result, to="DATETIME")
373373

374-
if expr.dtype in (dtypes.STRING_DTYPE, dtypes.TIMESTAMP_DTYPE):
374+
if expr.dtype in (
375+
dtypes.STRING_DTYPE,
376+
dtypes.TIMESTAMP_DTYPE,
377+
dtypes.DATETIME_DTYPE,
378+
dtypes.DATE_DTYPE,
379+
):
375380
return sge.TryCast(this=expr.expr, to="DATETIME")
376381

377382
value = expr.expr
@@ -396,7 +401,12 @@ def _(expr: TypedExpr, op: ops.ToTimestampOp) -> sge.Expression:
396401
"PARSE_TIMESTAMP", sge.convert(op.format), expr.expr, sge.convert("UTC")
397402
)
398403

399-
if expr.dtype in (dtypes.STRING_DTYPE, dtypes.DATETIME_DTYPE):
404+
if expr.dtype in (
405+
dtypes.STRING_DTYPE,
406+
dtypes.DATETIME_DTYPE,
407+
dtypes.TIMESTAMP_DTYPE,
408+
dtypes.DATE_DTYPE,
409+
):
400410
return sge.func("TIMESTAMP", expr.expr)
401411

402412
value = expr.expr

bigframes/core/compile/sqlglot/sql/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
table,
2323
to_sql,
2424
)
25+
from bigframes.core.compile.sqlglot.sql.ddl import create_external_table, load_data
2526
from bigframes.core.compile.sqlglot.sql.dml import insert, replace
2627

2728
__all__ = [
@@ -33,6 +34,9 @@
3334
"literal",
3435
"table",
3536
"to_sql",
37+
# From ddl.py
38+
"create_external_table",
39+
"load_data",
3640
# From dml.py
3741
"insert",
3842
"replace",

0 commit comments

Comments
 (0)