GeezerVison is showing github.com — feat: add holiday regions for vertex forecasting (#1253) · googleapis/python-aiplatform@0036ab0
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: google/cloud/aiplatform/training_jobs.py +31-1Lines changed: 31 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -4044,6 +4044,7 @@ def run( | 4044 | 4044 | window_column: Optional[str] = None, | 4045 | 4045 | window_stride_length: Optional[int] = None, | 4046 | 4046 | window_max_count: Optional[int] = None, | | 4047 | + holiday_regions: Optional[List[str]] = None, | 4047 | 4048 | sync: bool = True, | 4048 | 4049 | create_request_timeout: Optional[float] = None, | 4049 | 4050 | ) -> models.Model: | @@ -4238,10 +4239,23 @@ def run( | 4238 | 4239 | Optional. Number of rows that should be used to generate input | 4239 | 4240 | examples. If the total row count is larger than this number, the | 4240 | 4241 | input data will be randomly sampled to hit the count. | | 4242 | + holiday_regions (List[str]): | | 4243 | + Optional. The geographical regions to use when creating holiday | | 4244 | + features. This option is only allowed when data_granularity_unit | | 4245 | + is ``day``. Acceptable values can come from any of the following | | 4246 | + levels: | | 4247 | + Top level: GLOBAL | | 4248 | + Second level: continental regions | | 4249 | + NA: North America | | 4250 | + JAPAC: Japan and Asia Pacific | | 4251 | + EMEA: Europe, the Middle East and Africa | | 4252 | + LAC: Latin America and the Caribbean | | 4253 | + Third level: countries from ISO 3166-1 Country codes. | 4241 | 4254 | sync (bool): | 4242 | | - Whether to execute this method synchronously. If False, this method | | 4255 | + Optional. Whether to execute this method synchronously. If False, this method | 4243 | 4256 | will be executed in concurrent Future and any downstream object will | 4244 | 4257 | be immediately returned and synced when the Future has completed. | | 4258 | +
| 4245 | 4259 | Returns: | 4246 | 4260 | model: The trained Vertex AI Model resource or None if training did not | 4247 | 4261 | produce a Vertex AI Model. | @@ -4299,6 +4313,7 @@ def run( | 4299 | 4313 | window_column=window_column, | 4300 | 4314 | window_stride_length=window_stride_length, | 4301 | 4315 | window_max_count=window_max_count, | | 4316 | + holiday_regions=holiday_regions, | 4302 | 4317 | sync=sync, | 4303 | 4318 | create_request_timeout=create_request_timeout, | 4304 | 4319 | ) | @@ -4338,6 +4353,7 @@ def _run( | 4338 | 4353 | window_column: Optional[str] = None, | 4339 | 4354 | window_stride_length: Optional[int] = None, | 4340 | 4355 | window_max_count: Optional[int] = None, | | 4356 | + holiday_regions: Optional[List[str]] = None, | 4341 | 4357 | sync: bool = True, | 4342 | 4358 | create_request_timeout: Optional[float] = None, | 4343 | 4359 | ) -> models.Model: | @@ -4536,12 +4552,25 @@ def _run( | 4536 | 4552 | Optional. Number of rows that should be used to generate input | 4537 | 4553 | examples. If the total row count is larger than this number, the | 4538 | 4554 | input data will be randomly sampled to hit the count. | | 4555 | + holiday_regions (List[str]): | | 4556 | + Optional. The geographical regions to use when creating holiday | | 4557 | + features. This option is only allowed when data_granularity_unit | | 4558 | + is ``day``. Acceptable values can come from any of the following | | 4559 | + levels: | | 4560 | + Top level: GLOBAL | | 4561 | + Second level: continental regions | | 4562 | + NA: North America | | 4563 | + JAPAC: Japan and Asia Pacific | | 4564 | + EMEA: Europe, the Middle East and Africa | | 4565 | + LAC: Latin America and the Caribbean | | 4566 | + Third level: countries from ISO 3166-1 Country codes. | 4539 | 4567 | sync (bool): | 4540 | 4568 | Whether to execute this method synchronously. If False, this method | 4541 | 4569 | will be executed in concurrent Future and any downstream object will | 4542 | 4570 | be immediately returned and synced when the Future has completed. | 4543 | 4571 | create_request_timeout (float): | 4544 | 4572 | Optional. The timeout for the create request in seconds. | | 4573 | +
| 4545 | 4574 | Returns: | 4546 | 4575 | model: The trained Vertex AI Model resource or None if training did not | 4547 | 4576 | produce a Vertex AI Model. | @@ -4592,6 +4621,7 @@ def _run( | 4592 | 4621 | "quantiles": quantiles, | 4593 | 4622 | "validationOptions": validation_options, | 4594 | 4623 | "optimizationObjective": self._optimization_objective, | | 4624 | + "holidayRegions": holiday_regions, | 4595 | 4625 | } | 4596 | 4626 |
| 4597 | 4627 | # TODO(TheMichaelHu): Remove the ifs once the API supports these inputs. | |
Collapse file Copy file name to clipboardExpand all lines: tests/unit/aiplatform/test_automl_forecasting_training_jobs.py +13Lines changed: 13 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 88 | 88 | _TEST_WINDOW_COLUMN = None | 89 | 89 | _TEST_WINDOW_STRIDE_LENGTH = 1 | 90 | 90 | _TEST_WINDOW_MAX_COUNT = None | | 91 | +_TEST_TRAINING_HOLIDAY_REGIONS = ["GLOBAL"] | 91 | 92 | _TEST_TRAINING_TASK_INPUTS_DICT = { | 92 | 93 | # required inputs | 93 | 94 | "targetColumn": _TEST_TRAINING_TARGET_COLUMN, | | 122 | 123 | "windowConfig": { | 123 | 124 | "strideLength": _TEST_WINDOW_STRIDE_LENGTH, | 124 | 125 | }, | | 126 | + "holidayRegions": _TEST_TRAINING_HOLIDAY_REGIONS, | 125 | 127 | } | 126 | 128 |
| 127 | 129 | _TEST_TRAINING_TASK_INPUTS_WITH_ADDITIONAL_EXPERIMENTS = json_format.ParseDict( | @@ -322,6 +324,7 @@ def test_run_call_pipeline_service_create( | 322 | 324 | window_max_count=_TEST_WINDOW_MAX_COUNT, | 323 | 325 | sync=sync, | 324 | 326 | create_request_timeout=None, | | 327 | + holiday_regions=_TEST_TRAINING_HOLIDAY_REGIONS, | 325 | 328 | ) | 326 | 329 |
| 327 | 330 | if not sync: | @@ -417,6 +420,7 @@ def test_run_call_pipeline_service_create_with_timeout( | 417 | 420 | window_max_count=_TEST_WINDOW_MAX_COUNT, | 418 | 421 | sync=sync, | 419 | 422 | create_request_timeout=180.0, | | 423 | + holiday_regions=_TEST_TRAINING_HOLIDAY_REGIONS, | 420 | 424 | ) | 421 | 425 |
| 422 | 426 | if not sync: | @@ -494,6 +498,7 @@ def test_run_call_pipeline_if_no_model_display_name_nor_model_labels( | 494 | 498 | window_max_count=_TEST_WINDOW_MAX_COUNT, | 495 | 499 | sync=sync, | 496 | 500 | create_request_timeout=None, | | 501 | + holiday_regions=_TEST_TRAINING_HOLIDAY_REGIONS, | 497 | 502 | ) | 498 | 503 |
| 499 | 504 | if not sync: | @@ -571,6 +576,7 @@ def test_run_call_pipeline_if_set_additional_experiments( | 571 | 576 | window_max_count=_TEST_WINDOW_MAX_COUNT, | 572 | 577 | sync=sync, | 573 | 578 | create_request_timeout=None, | | 579 | + holiday_regions=_TEST_TRAINING_HOLIDAY_REGIONS, | 574 | 580 | ) | 575 | 581 |
| 576 | 582 | if not sync: | @@ -644,6 +650,7 @@ def test_run_called_twice_raises( | 644 | 650 | window_stride_length=_TEST_WINDOW_STRIDE_LENGTH, | 645 | 651 | window_max_count=_TEST_WINDOW_MAX_COUNT, | 646 | 652 | sync=sync, | | 653 | + holiday_regions=_TEST_TRAINING_HOLIDAY_REGIONS, | 647 | 654 | ) | 648 | 655 |
| 649 | 656 | with pytest.raises(RuntimeError): | @@ -675,6 +682,7 @@ def test_run_called_twice_raises( | 675 | 682 | window_stride_length=_TEST_WINDOW_STRIDE_LENGTH, | 676 | 683 | window_max_count=_TEST_WINDOW_MAX_COUNT, | 677 | 684 | sync=sync, | | 685 | + holiday_regions=_TEST_TRAINING_HOLIDAY_REGIONS, | 678 | 686 | ) | 679 | 687 |
| 680 | 688 | @pytest.mark.parametrize("sync", [True, False]) | @@ -722,6 +730,7 @@ def test_run_raises_if_pipeline_fails( | 722 | 730 | window_stride_length=_TEST_WINDOW_STRIDE_LENGTH, | 723 | 731 | window_max_count=_TEST_WINDOW_MAX_COUNT, | 724 | 732 | sync=sync, | | 733 | + holiday_regions=_TEST_TRAINING_HOLIDAY_REGIONS, | 725 | 734 | ) | 726 | 735 |
| 727 | 736 | if not sync: | @@ -805,6 +814,7 @@ def test_splits_fraction( | 805 | 814 | window_max_count=_TEST_WINDOW_MAX_COUNT, | 806 | 815 | sync=sync, | 807 | 816 | create_request_timeout=None, | | 817 | + holiday_regions=_TEST_TRAINING_HOLIDAY_REGIONS, | 808 | 818 | ) | 809 | 819 |
| 810 | 820 | if not sync: | @@ -900,6 +910,7 @@ def test_splits_timestamp( | 900 | 910 | window_max_count=_TEST_WINDOW_MAX_COUNT, | 901 | 911 | sync=sync, | 902 | 912 | create_request_timeout=None, | | 913 | + holiday_regions=_TEST_TRAINING_HOLIDAY_REGIONS, | 903 | 914 | ) | 904 | 915 |
| 905 | 916 | if not sync: | @@ -993,6 +1004,7 @@ def test_splits_predefined( | 993 | 1004 | window_max_count=_TEST_WINDOW_MAX_COUNT, | 994 | 1005 | sync=sync, | 995 | 1006 | create_request_timeout=None, | | 1007 | + holiday_regions=_TEST_TRAINING_HOLIDAY_REGIONS, | 996 | 1008 | ) | 997 | 1009 |
| 998 | 1010 | if not sync: | @@ -1081,6 +1093,7 @@ def test_splits_default( | 1081 | 1093 | window_max_count=_TEST_WINDOW_MAX_COUNT, | 1082 | 1094 | sync=sync, | 1083 | 1095 | create_request_timeout=None, | | 1096 | + holiday_regions=_TEST_TRAINING_HOLIDAY_REGIONS, | 1084 | 1097 | ) | 1085 | 1098 |
| 1086 | 1099 | if not sync: | |
|