Skip to content

Commit

Permalink
feat: add holiday regions for vertex forecasting (#1253)
Browse files Browse the repository at this point in the history
Add holiday regions for Vertex Forecasting.

---

Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly:
- [x] Make sure to open an issue as a [bug/issue](https://github.com/googleapis/python-aiplatform/issues/new/choose) before writing your code!  That way we can discuss the change, evaluate designs, and agree on the general idea
- [x] Ensure the tests and linter pass
- [x] Code coverage does not decrease (if any source code was changed)
- [x] Appropriate docs were updated (if necessary)

Fixes b/232964228 🦕
  • Loading branch information
TheMichaelHu authored May 27, 2022
1 parent a3da19a commit 0036ab0
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
32 changes: 31 additions & 1 deletion google/cloud/aiplatform/training_jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -4044,6 +4044,7 @@ def run(
window_column: Optional[str] = None,
window_stride_length: Optional[int] = None,
window_max_count: Optional[int] = None,
holiday_regions: Optional[List[str]] = None,
sync: bool = True,
create_request_timeout: Optional[float] = None,
) -> models.Model:
Expand Down Expand Up @@ -4238,10 +4239,23 @@ def run(
Optional. Number of rows that should be used to generate input
examples. If the total row count is larger than this number, the
input data will be randomly sampled to hit the count.
holiday_regions (List[str]):
Optional. The geographical regions to use when creating holiday
features. This option is only allowed when data_granularity_unit
is ``day``. Acceptable values can come from any of the following
levels:
Top level: GLOBAL
Second level: continental regions
NA: North America
JAPAC: Japan and Asia Pacific
EMEA: Europe, the Middle East and Africa
LAC: Latin America and the Caribbean
Third level: countries from ISO 3166-1 Country codes.
sync (bool):
Whether to execute this method synchronously. If False, this method
Optional. Whether to execute this method synchronously. If False, this method
will be executed in concurrent Future and any downstream object will
be immediately returned and synced when the Future has completed.
Returns:
model: The trained Vertex AI Model resource or None if training did not
produce a Vertex AI Model.
Expand Down Expand Up @@ -4299,6 +4313,7 @@ def run(
window_column=window_column,
window_stride_length=window_stride_length,
window_max_count=window_max_count,
holiday_regions=holiday_regions,
sync=sync,
create_request_timeout=create_request_timeout,
)
Expand Down Expand Up @@ -4338,6 +4353,7 @@ def _run(
window_column: Optional[str] = None,
window_stride_length: Optional[int] = None,
window_max_count: Optional[int] = None,
holiday_regions: Optional[List[str]] = None,
sync: bool = True,
create_request_timeout: Optional[float] = None,
) -> models.Model:
Expand Down Expand Up @@ -4536,12 +4552,25 @@ def _run(
Optional. Number of rows that should be used to generate input
examples. If the total row count is larger than this number, the
input data will be randomly sampled to hit the count.
holiday_regions (List[str]):
Optional. The geographical regions to use when creating holiday
features. This option is only allowed when data_granularity_unit
is ``day``. Acceptable values can come from any of the following
levels:
Top level: GLOBAL
Second level: continental regions
NA: North America
JAPAC: Japan and Asia Pacific
EMEA: Europe, the Middle East and Africa
LAC: Latin America and the Caribbean
Third level: countries from ISO 3166-1 Country codes.
sync (bool):
Whether to execute this method synchronously. If False, this method
will be executed in concurrent Future and any downstream object will
be immediately returned and synced when the Future has completed.
create_request_timeout (float):
Optional. The timeout for the create request in seconds.
Returns:
model: The trained Vertex AI Model resource or None if training did not
produce a Vertex AI Model.
Expand Down Expand Up @@ -4592,6 +4621,7 @@ def _run(
"quantiles": quantiles,
"validationOptions": validation_options,
"optimizationObjective": self._optimization_objective,
"holidayRegions": holiday_regions,
}

# TODO(TheMichaelHu): Remove the ifs once the API supports these inputs.
Expand Down
13 changes: 13 additions & 0 deletions tests/unit/aiplatform/test_automl_forecasting_training_jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
_TEST_WINDOW_COLUMN = None
_TEST_WINDOW_STRIDE_LENGTH = 1
_TEST_WINDOW_MAX_COUNT = None
_TEST_TRAINING_HOLIDAY_REGIONS = ["GLOBAL"]
_TEST_TRAINING_TASK_INPUTS_DICT = {
# required inputs
"targetColumn": _TEST_TRAINING_TARGET_COLUMN,
Expand Down Expand Up @@ -122,6 +123,7 @@
"windowConfig": {
"strideLength": _TEST_WINDOW_STRIDE_LENGTH,
},
"holidayRegions": _TEST_TRAINING_HOLIDAY_REGIONS,
}

_TEST_TRAINING_TASK_INPUTS_WITH_ADDITIONAL_EXPERIMENTS = json_format.ParseDict(
Expand Down Expand Up @@ -322,6 +324,7 @@ def test_run_call_pipeline_service_create(
window_max_count=_TEST_WINDOW_MAX_COUNT,
sync=sync,
create_request_timeout=None,
holiday_regions=_TEST_TRAINING_HOLIDAY_REGIONS,
)

if not sync:
Expand Down Expand Up @@ -417,6 +420,7 @@ def test_run_call_pipeline_service_create_with_timeout(
window_max_count=_TEST_WINDOW_MAX_COUNT,
sync=sync,
create_request_timeout=180.0,
holiday_regions=_TEST_TRAINING_HOLIDAY_REGIONS,
)

if not sync:
Expand Down Expand Up @@ -494,6 +498,7 @@ def test_run_call_pipeline_if_no_model_display_name_nor_model_labels(
window_max_count=_TEST_WINDOW_MAX_COUNT,
sync=sync,
create_request_timeout=None,
holiday_regions=_TEST_TRAINING_HOLIDAY_REGIONS,
)

if not sync:
Expand Down Expand Up @@ -571,6 +576,7 @@ def test_run_call_pipeline_if_set_additional_experiments(
window_max_count=_TEST_WINDOW_MAX_COUNT,
sync=sync,
create_request_timeout=None,
holiday_regions=_TEST_TRAINING_HOLIDAY_REGIONS,
)

if not sync:
Expand Down Expand Up @@ -644,6 +650,7 @@ def test_run_called_twice_raises(
window_stride_length=_TEST_WINDOW_STRIDE_LENGTH,
window_max_count=_TEST_WINDOW_MAX_COUNT,
sync=sync,
holiday_regions=_TEST_TRAINING_HOLIDAY_REGIONS,
)

with pytest.raises(RuntimeError):
Expand Down Expand Up @@ -675,6 +682,7 @@ def test_run_called_twice_raises(
window_stride_length=_TEST_WINDOW_STRIDE_LENGTH,
window_max_count=_TEST_WINDOW_MAX_COUNT,
sync=sync,
holiday_regions=_TEST_TRAINING_HOLIDAY_REGIONS,
)

@pytest.mark.parametrize("sync", [True, False])
Expand Down Expand Up @@ -722,6 +730,7 @@ def test_run_raises_if_pipeline_fails(
window_stride_length=_TEST_WINDOW_STRIDE_LENGTH,
window_max_count=_TEST_WINDOW_MAX_COUNT,
sync=sync,
holiday_regions=_TEST_TRAINING_HOLIDAY_REGIONS,
)

if not sync:
Expand Down Expand Up @@ -805,6 +814,7 @@ def test_splits_fraction(
window_max_count=_TEST_WINDOW_MAX_COUNT,
sync=sync,
create_request_timeout=None,
holiday_regions=_TEST_TRAINING_HOLIDAY_REGIONS,
)

if not sync:
Expand Down Expand Up @@ -900,6 +910,7 @@ def test_splits_timestamp(
window_max_count=_TEST_WINDOW_MAX_COUNT,
sync=sync,
create_request_timeout=None,
holiday_regions=_TEST_TRAINING_HOLIDAY_REGIONS,
)

if not sync:
Expand Down Expand Up @@ -993,6 +1004,7 @@ def test_splits_predefined(
window_max_count=_TEST_WINDOW_MAX_COUNT,
sync=sync,
create_request_timeout=None,
holiday_regions=_TEST_TRAINING_HOLIDAY_REGIONS,
)

if not sync:
Expand Down Expand Up @@ -1081,6 +1093,7 @@ def test_splits_default(
window_max_count=_TEST_WINDOW_MAX_COUNT,
sync=sync,
create_request_timeout=None,
holiday_regions=_TEST_TRAINING_HOLIDAY_REGIONS,
)

if not sync:
Expand Down

0 comments on commit 0036ab0

Please sign in to comment.