def __post_init__(self) -> None: if isinstance(self.target, list) and len(self.target) == 1: self.target = self.target[0] self.one_dim_target = not isinstance(self.target, list) self.process = ProcessDataEntry(self.freq, one_dim_target=self.one_dim_target) # store data internally as List[Tuple[str, pandas.DataFrame]] # if str is not empty it will be set in ``DataEntry`` as ``item_id``. if isinstance(self.dataframes, dict): self._dataframes = list(self.dataframes.items()) elif isinstance(self.dataframes, list): self._dataframes = [("", df) for df in self.dataframes] else: # case single dataframe self._dataframes = [("", self.dataframes)]
def test_timeseries_item_serialization() -> None: ts_item = TimeSeriesItem( item="1", start="2014-09-07 00:00:00", target=[1, 2], feat_static_cat=[1], ) metadata = MetaData( freq="1H", feat_static_cat=[{"name": "feat_static_cat_000", "cardinality": 1}], ) process = ProcessDataEntry(freq=metadata.freq) data_entry = process(ts_item.gluontsify(metadata)) serialized_data = serialize_data_entry(data_entry) deserialized_ts_item = TimeSeriesItem(**serialized_data) assert deserialized_ts_item == ts_item