Skip to content

Commit 3dcae2d

Browse files
rey-esptswast
andauthored
docs: add snippet to evaluate ARIMA plus model in the Forecast a single time series with a univariate model tutorial (#1267)
* merge main * details * Update samples/snippets/create_single_timeseries_forecasting_model_test.py Co-authored-by: Tim Sweña (Swast) <swast@google.com> * expand ibis to bq type conversion * added unit test for from_ibis --------- Co-authored-by: Tim Sweña (Swast) <swast@google.com>
1 parent c16b3a8 commit 3dcae2d

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

‎samples/snippets/create_single_timeseries_forecasting_model_test.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,27 @@ def test_create_single_timeseries() -> None:
7272
# Expected output:
7373
# ar_coefficients ma_coefficients intercept_or_drift
7474
# 0 [0.40944762] [-0.81168198] 0.0
75-
7675
# [END bigquery_dataframes_single_timeseries_forecasting_model_tutorial_coef]
76+
77+
# [START bigquery_dataframes_single_timeseries_forecasting_model_tutorial_evaluate]
78+
# Evaluate the time series models by using the summary() function. The summary()
79+
# function shows you the evaluation metrics of all the candidate models evaluated
80+
# during the process of automatic hyperparameter tuning.
81+
summary = model.summary(
82+
show_all_candidate_models=True,
83+
)
84+
print(summary.peek())
85+
86+
# Expected output:
87+
# row non_seasonal_p non_seasonal_d non_seasonal_q has_drift log_likelihood AIC variance seasonal_periods has_holiday_effect has_spikes_and_dips has_step_changes error_message
88+
# 0 0 1 3 True -2464.255656 4938.511313 42772.506055 ['WEEKLY'] False False True
89+
# 1 2 1 0 False -2473.141651 4952.283303 44942.416463 ['WEEKLY'] False False True
90+
# 2 1 1 0 False -2479.880885 4963.76177 46642.953433 ['WEEKLY'] False False True
91+
# 3 0 1 1 False -2470.632377 4945.264753 44319.379307 ['WEEKLY'] False False True
92+
# 4 2 1 1 True -2463.671247 4937.342493 42633.299513 ['WEEKLY'] False False True
93+
# [END bigquery_dataframes_single_timeseries_forecasting_model_tutorial_evaluate]
7794
assert coef is not None
95+
assert summary is not None
7896
assert model is not None
7997
assert parsed_date is not None
8098
assert total_visits is not None

‎tests/unit/core/test_dtypes.py

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

15+
import bigframes_vendored.ibis.backends.bigquery.datatypes as ibis_bq_types
1516
import bigframes_vendored.ibis.expr.datatypes as ibis_dtypes
1617
import bigframes_vendored.ibis.expr.types as ibis_types
1718
import geopandas as gpd # type: ignore
@@ -152,6 +153,15 @@ def test_ibis_dtype_to_arrow_dtype(ibis_dtype, arrow_dtype):
152153
assert result == arrow_dtype
153154

154155

156+
@pytest.mark.parametrize(
157+
("ibis_dtype", "bigquery_type"),
158+
[(ibis_dtypes.String(), "STRING"), (ibis_dtypes.String(nullable=False), "STRING")],
159+
)
160+
def test_ibis_dtype_to_bigquery_type(ibis_dtype, bigquery_type):
161+
result = ibis_bq_types.BigQueryType.from_ibis(ibis_dtype)
162+
assert result == bigquery_type
163+
164+
155165
@pytest.mark.parametrize(
156166
["bigframes_dtype", "ibis_dtype"],
157167
[

‎third_party/bigframes_vendored/ibis/backends/bigquery/datatypes.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ def from_ibis(cls, dtype: dt.DataType) -> str:
5555
return "INT64"
5656
elif dtype.is_binary():
5757
return "BYTES"
58+
elif dtype.is_string():
59+
return "STRING"
5860
elif dtype.is_date():
5961
return "DATE"
6062
elif dtype.is_timestamp():

0 commit comments

Comments
 (0)