class_docstr: Synthetic data set generated by providing a recipe.
  
  A recipe is either a (non-deterministic) function
  
      f(length: int, global_state: dict) -> dict
  
  or list of (field, function) tuples of the form
  
      (field: str, f(data: dict, length: int, global_state: dict) -> dict)
  
  which is processed sequentially, with data initially set to {},
  and each entry updating data[field] to the output of the function
  call.
class_docstr_tok: ["Synthetic","data","set","generated","by","providing","a","recipe",".","A","recipe","is","either","a","(","non-deterministic",")","function","f","(","length",":","int",",","global_state",":","dict",")","-",">","dict","or","list","of","(","field",",","function",")","tuples","of","the","form","(","field",":","str",",","f","(","data",":","dict",",","length",":","int",",","global_state",":","dict",")","-",">","dict",")","which","is","processed","sequentially",",","with","data","initially","set","to","{","}",",","and","each","entry","updating","data","[","field","]","to","the","output","of","the","function","call","."]
docstr: Trim a DataEntry into a training range, by removing the last
  prediction_length time points from the target and dynamic features.
code: def trim_ts_item_end(x: DataEntry, length: int) -> DataEntry:
      """
      Trim a DataEntry into a training range, by removing the last
      prediction_length time points from the target and dynamic features.
      """
      y = dict(
          item_id=x[FieldName.ITEM_ID],
          start=x[FieldName.START],
          target=x[FieldName.TARGET][:-length],
      )
  
      if FieldName.FEAT_DYNAMIC_CAT in x:
          y[FieldName.FEAT_DYNAMIC_CAT] = x[FieldName.FEAT_DYNAMIC_CAT][
              :, :-length
          ]
      if FieldName.FEAT_DYNAMIC_REAL in x:
          y[FieldName.FEAT_DYNAMIC_REAL] = x[
              FieldName.FEAT_DYNAMIC_REAL
          ][:, :-length]
      return y
  
imports: import math
  import random
  from abc import abstractmethod
  from typing import Callable, Dict, List, NamedTuple, Optional, Tuple, Union, cast
  import numpy
  import pandas
  from pandas.tseries.frequencies import to_offset
  from pandas.tseries.offsets import BaseOffset, Week
  from gluonts.dataset.artificial.recipe import BinaryHolidays, BinaryMarkovChain, Constant, ForEachCat, Lag, LinearTrend, RandomCat, RandomGaussian, Stack, generate, take_as_list
  from gluonts.dataset.common import BasicFeatureInfo, CategoricalFeatureInfo, DataEntry, Dataset, ListDataset, MetaData, TrainDatasets
  from gluonts.dataset.field_names import FieldName
  from gluonts.dataset.stat import DatasetStatistics, calculate_dataset_statistics
label_desc: Use image node_id 6 for calling the RecipeDataset obj's underlying member method code with example usage: obj.trim_ts_item_end(x, length) and returns: y