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

Commit f949fe1

Browse files
feat: Update ai.forecast accessor per PR review
* Updated documentation to refer to BigQuery AI.FORECAST syntax. * Removed internal implementation details (`read_pandas` and `to_pandas`) from docstring. * Added missing `output_historical_time_series` parameter. * Added missing copyright headers to `tests/system/small/extensions/test_dataframe_accessor.py`. Co-authored-by: tswast <247555+tswast@users.noreply.github.com>
1 parent c3fdcbb commit f949fe1

File tree

4 files changed

+42
-4
lines changed

4 files changed

+42
-4
lines changed

bigframes/extensions/pandas/dataframe_accessor.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,13 @@ def forecast(
3939
horizon: int = 10,
4040
confidence_level: float = 0.95,
4141
context_window: Optional[int] = None,
42+
output_historical_time_series: bool = False,
4243
session=None,
4344
) -> pandas.DataFrame:
4445
"""
4546
Forecast time series at future horizon using BigQuery AI.FORECAST.
4647
47-
The DataFrame is converted to BigFrames by calling ``read_pandas``, then the forecast
48-
is generated using ``bigframes.bigquery.ai.forecast``, and the result is
49-
converted back to a pandas DataFrame using ``to_pandas``.
48+
See: https://cloud.google.com/bigquery/docs/reference/standard-sql/bigqueryml-syntax-ai-forecast
5049
5150
Args:
5251
data_col (str):
@@ -57,7 +56,7 @@ def forecast(
5756
The time points column provides the time points used to generate the forecast.
5857
The time points column must use one of the following data types: TIMESTAMP, DATE and DATETIME
5958
model (str, default "TimesFM 2.0"):
60-
A str value that specifies the name of the model. TimesFM 2.0 is the only supported value, and is the default value.
59+
A str value that specifies the name of the model. "TimesFM 2.0" and "TimesFM 2.5" are supported.
6160
id_cols (Iterable[str], optional):
6261
An iterable of str value that specifies the names of one or more ID columns. Each ID identifies a unique time series to forecast.
6362
Specify one or more values for this argument in order to forecast multiple time series using a single query.
@@ -72,6 +71,8 @@ def forecast(
7271
The context window length determines how many of the most recent data points from the input time series are use by the model.
7372
If you don't specify a value, the AI.FORECAST function automatically chooses the smallest possible context window length to use
7473
that is still large enough to cover the number of time series data points in your input data.
74+
output_historical_time_series (bool, default False):
75+
A boolean value that determines whether to include the input time series history in the forecast.
7576
session (bigframes.session.Session, optional):
7677
The BigFrames session to use. If not provided, the default global session is used.
7778
@@ -94,6 +95,7 @@ def forecast(
9495
horizon=horizon,
9596
confidence_level=confidence_level,
9697
context_window=context_window,
98+
output_historical_time_series=output_historical_time_series,
9799
)
98100
return result.to_pandas(ordered=True)
99101

patch_tests.diff

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<<<<<<< SEARCH
2+
import pandas as pd
3+
import pytest
4+
=======
5+
# Copyright 2026 Google LLC
6+
#
7+
# Licensed under the Apache License, Version 2.0 (the "License");
8+
# you may not use this file except in compliance with the License.
9+
# You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing, software
14+
# distributed under the License is distributed on an "AS IS" BASIS,
15+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
# See the License for the specific language governing permissions and
17+
# limitations under the License.
18+
19+
import pandas as pd
20+
import pytest
21+
>>>>>>> REPLACE

tests/system/small/extensions/test_dataframe_accessor.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
# Copyright 2026 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
115
import pandas as pd
216
import pytest
317

tests/unit/core/compile/sqlglot/test_dataframe_accessor.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,5 @@ def mock_ai_forecast(df, **kwargs):
7878
"horizon": 5,
7979
"confidence_level": 0.95,
8080
"context_window": None,
81+
"output_historical_time_series": False,
8182
}

0 commit comments

Comments
 (0)