def period_from_list(period: Tuple[int, List[int]]) -> dateslib.PeriodTensor: """Utility to convert a list of periods to a PeriodTensor. Args: period: A tuple of an integer (which corresponds to the proto type of the period (see `period_pb2.Period`)) and a list of period values. Returns: An instance of the `PeriodTensor`. """ amount = period[1] period_type = period_pb2.PeriodType.Name(period[0]) return dateslib.PeriodTensor(amount, dateslib.PeriodType[period_type])
def period_from_dict(period: Dict[int, List[int]]) -> dateslib.PeriodTensor: """Utility to convert a dictionary of periods to a PeriodTensor. Args: period: A dictionary with keys "type" (which corresponds to the proto type of the period (see `period_pb2.Period`)) and "frequency". Returns: An instance of the `PeriodTensor`. """ amount = period["frequency"] period_type = period_pb2.PeriodType.Name(period["type"]) return dateslib.PeriodTensor(amount, dateslib.PeriodType[period_type])
def get_period(period: period_pb2.Period) -> dateslib.PeriodTensor: period_type = period_pb2.PeriodType.Name(period.type) return dateslib.PeriodTensor( period.amount + tf.compat.v1.placeholder_with_default(0, []), dateslib.PeriodType[period_type])
def get_period(period: period_pb2.Period) -> dateslib.PeriodTensor: period_type = period_pb2.PeriodType.Name(period.type) return dateslib.PeriodTensor(period.amount, dateslib.PeriodType[period_type])