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

Commit 389af07

Browse files
committed
docs: reduce redundancy
1 parent 66fb4ab commit 389af07

File tree

3 files changed

+42
-83
lines changed

3 files changed

+42
-83
lines changed

bigframes/bigquery/_operations/ai.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -893,6 +893,25 @@ def forecast(
893893
and might have limited support. For more information, see the launch stage descriptions
894894
(https://cloud.google.com/products#product-launch-stages).
895895
896+
**Examples:**
897+
898+
Forecast using a pandas DataFrame:
899+
900+
>>> import pandas as pd
901+
>>> import bigframes.pandas as bpd
902+
>>> df = pd.DataFrame({"value": [1, 2, 3], "time": pd.to_datetime(["2020-01-01", "2020-01-02", "2020-01-03"])})
903+
>>> bpd.options.display.progress_bar = None # doctest: +SKIP
904+
>>> forecasted_pandas_df = df.bigquery.ai.forecast(data_col="value", timestamp_col="time", horizon=2) # doctest: +SKIP
905+
>>> type(forecasted_pandas_df) # doctest: +SKIP
906+
<class 'pandas.core.frame.DataFrame'>
907+
908+
Forecast using a BigFrames DataFrame:
909+
910+
>>> bf_df = bpd.DataFrame({"value": [1, 2, 3], "time": pd.to_datetime(["2020-01-01", "2020-01-02", "2020-01-03"])})
911+
>>> forecasted_bf_df = bf_df.bigquery.ai.forecast(data_col="value", timestamp_col="time", horizon=2) # doctest: +SKIP
912+
>>> type(forecasted_bf_df) # doctest: +SKIP
913+
<class 'bigframes.dataframe.DataFrame'>
914+
896915
Args:
897916
df (DataFrame):
898917
The dataframe that contains the data that you want to forecast. It could be either a BigFrames Dataframe or

bigframes/bigquery/_operations/sql.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,25 @@ def sql_scalar(
7171
2 4.000000000
7272
dtype: decimal128(38, 9)[pyarrow]
7373
74+
You can also use the `.bigquery` DataFrame accessor to apply a SQL scalar function.
75+
76+
Compute SQL scalar using a pandas DataFrame:
77+
78+
>>> import pandas as pd
79+
>>> df = pd.DataFrame({"x": [1, 2, 3]})
80+
>>> bpd.options.display.progress_bar = None # doctest: +SKIP
81+
>>> pandas_s = df.bigquery.sql_scalar("POW({0}, 2)") # doctest: +SKIP
82+
>>> type(pandas_s) # doctest: +SKIP
83+
<class 'pandas.core.series.Series'>
84+
85+
Compute SQL scalar using a BigFrames DataFrame:
86+
87+
>>> bf_df = bpd.DataFrame({"x": [1, 2, 3]})
88+
>>> bf_s = bf_df.bigquery.sql_scalar("POW({0}, 2)") # doctest: +SKIP
89+
>>> type(bf_s) # doctest: +SKIP
90+
<class 'bigframes.series.Series'>
91+
92+
7493
Args:
7594
sql_template (str):
7695
A SQL format string with Python-style {0} placeholders for each of

bigframes/extensions/core/dataframe_accessor.py

Lines changed: 4 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -65,57 +65,8 @@ def forecast(
6565
"""
6666
Forecast time series at future horizon using BigQuery AI.FORECAST.
6767
68-
See: https://cloud.google.com/bigquery/docs/reference/standard-sql/bigqueryml-syntax-ai-forecast
69-
70-
Args:
71-
data_col (str):
72-
A str value that specifies the name of the data column. The data column contains the data to forecast.
73-
The data column must use one of the following data types: INT64, NUMERIC and FLOAT64
74-
timestamp_col (str):
75-
A str value that specified the name of the time points column.
76-
The time points column provides the time points used to generate the forecast.
77-
The time points column must use one of the following data types: TIMESTAMP, DATE and DATETIME
78-
model (str, default "TimesFM 2.0"):
79-
A str value that specifies the name of the model. "TimesFM 2.0" and "TimesFM 2.5" are supported.
80-
id_cols (Iterable[str], optional):
81-
An iterable of str value that specifies the names of one or more ID columns. Each ID identifies a unique time series to forecast.
82-
Specify one or more values for this argument in order to forecast multiple time series using a single query.
83-
The columns that you specify must use one of the following data types: STRING, INT64, ARRAY<STRING> and ARRAY<INT64>
84-
horizon (int, default 10):
85-
An int value that specifies the number of time points to forecast. The default value is 10. The valid input range is [1, 10,000].
86-
confidence_level (float, default 0.95):
87-
A FLOAT64 value that specifies the percentage of the future values that fall in the prediction interval.
88-
The default value is 0.95. The valid input range is [0, 1).
89-
context_window (int, optional):
90-
An int value that specifies the context window length used by BigQuery ML's built-in TimesFM model.
91-
The context window length determines how many of the most recent data points from the input time series are use by the model.
92-
If you don't specify a value, the AI.FORECAST function automatically chooses the smallest possible context window length to use
93-
that is still large enough to cover the number of time series data points in your input data.
94-
output_historical_time_series (bool, default False):
95-
A boolean value that determines whether to include the input time series history in the forecast.
96-
session (bigframes.session.Session, optional):
97-
The BigFrames session to use. If not provided, the default global session is used.
98-
99-
Returns:
100-
The forecast result DataFrame.
101-
102-
Examples:
103-
Forecast using a pandas DataFrame:
104-
105-
>>> import pandas as pd
106-
>>> import bigframes.pandas as bpd
107-
>>> df = pd.DataFrame({"value": [1, 2, 3], "time": pd.to_datetime(["2020-01-01", "2020-01-02", "2020-01-03"])})
108-
>>> bpd.options.display.progress_bar = None # doctest: +SKIP
109-
>>> forecasted_pandas_df = df.bigquery.ai.forecast(data_col="value", timestamp_col="time", horizon=2) # doctest: +SKIP
110-
>>> type(forecasted_pandas_df) # doctest: +SKIP
111-
<class 'pandas.core.frame.DataFrame'>
112-
113-
Forecast using a BigFrames DataFrame:
114-
115-
>>> bf_df = bpd.DataFrame({"value": [1, 2, 3], "time": pd.to_datetime(["2020-01-01", "2020-01-02", "2020-01-03"])})
116-
>>> forecasted_bf_df = bf_df.bigquery.ai.forecast(data_col="value", timestamp_col="time", horizon=2) # doctest: +SKIP
117-
>>> type(forecasted_bf_df) # doctest: +SKIP
118-
<class 'bigframes.dataframe.DataFrame'>
68+
This is an accessor for :func:`bigframes.bigquery.ai.forecast`. See that
69+
function's documentation for detailed parameter descriptions and examples.
11970
"""
12071
import bigframes.bigquery.ai
12172

@@ -162,38 +113,8 @@ def sql_scalar(
162113
"""
163114
Compute a new Series by applying a SQL scalar function to the DataFrame.
164115
165-
The SQL template is applied using ``bigframes.bigquery.sql_scalar``.
166-
167-
Args:
168-
sql_template (str):
169-
A SQL format string with Python-style {0}, {1}, etc. placeholders for each of
170-
the columns in the DataFrame (in the order they appear in ``df.columns``).
171-
output_dtype (a BigQuery DataFrames compatible dtype, optional):
172-
If provided, BigQuery DataFrames uses this to determine the output
173-
of the returned Series. This avoids a dry run query.
174-
session (bigframes.session.Session, optional):
175-
The BigFrames session to use. If not provided, the default global session is used.
176-
177-
Returns:
178-
The result of the SQL scalar function as a Series.
179-
180-
Examples:
181-
Compute SQL scalar using a pandas DataFrame:
182-
183-
>>> import pandas as pd
184-
>>> import bigframes.pandas as bpd
185-
>>> df = pd.DataFrame({"x": [1, 2, 3]})
186-
>>> bpd.options.display.progress_bar = None # doctest: +SKIP
187-
>>> pandas_s = df.bigquery.sql_scalar("POW({0}, 2)") # doctest: +SKIP
188-
>>> type(pandas_s) # doctest: +SKIP
189-
<class 'pandas.core.series.Series'>
190-
191-
Compute SQL scalar using a BigFrames DataFrame:
192-
193-
>>> bf_df = bpd.DataFrame({"x": [1, 2, 3]})
194-
>>> bf_s = bf_df.bigquery.sql_scalar("POW({0}, 2)") # doctest: +SKIP
195-
>>> type(bf_s) # doctest: +SKIP
196-
<class 'bigframes.series.Series'>
116+
This is an accessor for :func:`bigframes.bigquery.sql_scalar`. See that
117+
function's documentation for detailed parameter descriptions and examples.
197118
"""
198119
import bigframes.bigquery
199120

0 commit comments

Comments
 (0)