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)
| 74 | |
| 75 | |
| 76 | def time_features_from_frequency_str(freq_str: str) -> List[TimeFeature]: |
| 77 | """ |
| 78 | Returns a list of time features that will be appropriate for the given frequency string. |
| 79 | Parameters |
| 80 | ---------- |
| 81 | freq_str |
| 82 | Frequency string of the form [multiple][granularity] such as "12H", "5min", "1D" etc. |
| 83 | """ |
| 84 | |
| 85 | features_by_offsets = { |
| 86 | offsets.YearEnd: [], |
| 87 | offsets.QuarterEnd: [MonthOfYear], |
| 88 | offsets.MonthEnd: [MonthOfYear], |
| 89 | offsets.Week: [DayOfMonth, WeekOfYear], |
| 90 | offsets.Day: [DayOfWeek, DayOfMonth, DayOfYear], |
| 91 | offsets.BusinessDay: [DayOfWeek, DayOfMonth, DayOfYear], |
| 92 | offsets.Hour: [HourOfDay, DayOfWeek, DayOfMonth, DayOfYear], |
| 93 | offsets.Minute: [ |
| 94 | MinuteOfHour, |
| 95 | HourOfDay, |
| 96 | DayOfWeek, |
| 97 | DayOfMonth, |
| 98 | DayOfYear, |
| 99 | ], |
| 100 | offsets.Second: [ |
| 101 | SecondOfMinute, |
| 102 | MinuteOfHour, |
| 103 | HourOfDay, |
| 104 | DayOfWeek, |
| 105 | DayOfMonth, |
| 106 | DayOfYear, |
| 107 | ], |
| 108 | } |
| 109 | |
| 110 | offset = to_offset(freq_str) |
| 111 | |
| 112 | for offset_type, feature_classes in features_by_offsets.items(): |
| 113 | if isinstance(offset, offset_type): |
| 114 | return [cls() for cls in feature_classes] |
| 115 | |
| 116 | supported_freq_msg = f""" |
| 117 | Unsupported frequency {freq_str} |
| 118 | The following frequencies are supported: |
| 119 | Y - yearly |
| 120 | alias: A |
| 121 | M - monthly |
| 122 | W - weekly |
| 123 | D - daily |
| 124 | B - business days |
| 125 | H - hourly |
| 126 | T - minutely |
| 127 | alias: min |
| 128 | S - secondly |
| 129 | """ |
| 130 | raise RuntimeError(supported_freq_msg) |
| 131 | |
| 132 | |
| 133 | def time_features(dates, freq='h'): |