-
Notifications
You must be signed in to change notification settings - Fork 17
[ML-50316] Refactor frequency_unit and frequency_quantity in automl runtime #165
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 2 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
# | ||
# Copyright (C) 2022 Databricks, Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
from dataclasses import dataclass | ||
from typing import ClassVar, Set | ||
|
||
@dataclass(frozen=True) | ||
class Frequency: | ||
""" | ||
Represents the frequency of a time series. | ||
|
||
Attributes: | ||
frequency_unit (str): The unit of time for the frequency. | ||
frequency_quantity (int): The number of frequency_units in the period. | ||
|
||
Valid frequency units: source of truth is OFFSET_ALIAS_MAP in forecast.__init__.py | ||
- Weeks: "W", "W-SUN", "W-MON", "W-TUE", "W-WED", "W-THU", "W-FRI", "W-SAT" These are aliases for "W", used for DeepAR only | ||
- Days: "d", "D", "days", "day" | ||
- Hours: "hours", "hour", "hr", "h", "H | ||
- Minutes: "m", "minute", "min", "minutes", "T" | ||
- Seconds: "S", "seconds", "sec", "second" | ||
- Months: "M", "MS", "month", "months" | ||
- Quarters: "Q", "QS", "quarter", "quarters" | ||
- Years: "Y", "YS", "year", "years" | ||
|
||
Valid frequency quantities: | ||
- For minutes: {1, 5, 10, 15, 30} | ||
- For all other units: {1} | ||
""" | ||
|
||
VALID_FREQUENCY_UNITS: ClassVar[Set[str]] = { | ||
"W", "W-SUN", "W-MON", "W-TUE", "W-WED", "W-THU", "W-FRI", "W-SAT", | ||
"d", "D", "days", "day", "hours", "hour", "hr", "h", "H", | ||
"m", "minute", "min", "minutes", "T", "S", "seconds", | ||
"sec", "second", "M", "MS", "month", "months", "Q", "QS", "quarter", | ||
"quarters", "Y", "YS", "year", "years" | ||
} | ||
|
||
VALID_MINUTE_QUANTITIES: ClassVar[Set[int]] = {1, 5, 10, 15, 30} | ||
DEFAULT_QUANTITY: ClassVar[int] = 1 # Default for non-minute units | ||
|
||
frequency_unit: str | ||
frequency_quantity: int | ||
|
||
def __post_init__(self): | ||
if self.frequency_unit not in self.VALID_FREQUENCY_UNITS: | ||
raise ValueError(f"Invalid frequency unit: {self.frequency_unit}") | ||
|
||
if self.frequency_unit in {"m", "minute", "min", "minutes", "T"}: | ||
if self.frequency_quantity not in self.VALID_MINUTE_QUANTITIES: | ||
raise ValueError( | ||
f"Invalid frequency quantity {self.frequency_quantity} for minutes. " | ||
f"Allowed values: {sorted(self.VALID_MINUTE_QUANTITIES)}" | ||
) | ||
else: | ||
if self.frequency_quantity != self.DEFAULT_QUANTITY: | ||
raise ValueError( | ||
f"Invalid frequency quantity {self.frequency_quantity} for {self.frequency_unit}. " | ||
"Only 1 is allowed for this unit." | ||
) | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.