MCPcopy Create free account
hub / github.com/BorealisAI/scaleformer / time_features_from_frequency_str

Function time_features_from_frequency_str

utils/timefeatures.py:98–152  ·  view source on GitHub ↗

Returns a list of time features that will be appropriate for the given frequency string. Parameters ---------- freq_str Frequency string of the form [multiple][granularity] such as "12H", "5min", "1D" etc.

(freq_str: str)

Source from the content-addressed store, hash-verified

96
97
98def time_features_from_frequency_str(freq_str: str) -> List[TimeFeature]:
99 """
100 Returns a list of time features that will be appropriate for the given frequency string.
101 Parameters
102 ----------
103 freq_str
104 Frequency string of the form [multiple][granularity] such as "12H", "5min", "1D" etc.
105 """
106
107 features_by_offsets = {
108 offsets.YearEnd: [],
109 offsets.QuarterEnd: [MonthOfYear],
110 offsets.MonthEnd: [MonthOfYear],
111 offsets.Week: [DayOfMonth, WeekOfYear],
112 offsets.Day: [DayOfWeek, DayOfMonth, DayOfYear],
113 offsets.BusinessDay: [DayOfWeek, DayOfMonth, DayOfYear],
114 offsets.Hour: [HourOfDay, DayOfWeek, DayOfMonth, DayOfYear],
115 offsets.Minute: [
116 MinuteOfHour,
117 HourOfDay,
118 DayOfWeek,
119 DayOfMonth,
120 DayOfYear,
121 ],
122 offsets.Second: [
123 SecondOfMinute,
124 MinuteOfHour,
125 HourOfDay,
126 DayOfWeek,
127 DayOfMonth,
128 DayOfYear,
129 ],
130 }
131
132 offset = to_offset(freq_str)
133
134 for offset_type, feature_classes in features_by_offsets.items():
135 if isinstance(offset, offset_type):
136 return [cls() for cls in feature_classes]
137
138 supported_freq_msg = f"""
139 Unsupported frequency {freq_str}
140 The following frequencies are supported:
141 Y - yearly
142 alias: A
143 M - monthly
144 W - weekly
145 D - daily
146 B - business days
147 H - hourly
148 T - minutely
149 alias: min
150 S - secondly
151 """
152 raise RuntimeError(supported_freq_msg)
153
154
155def time_features(dates, freq='h'):

Callers 1

time_featuresFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected