code: def test_hts_to_dataset(mode: str):
      S = np.vstack(
          ([[1, 1, 1, 1], [1, 1, 0, 0], [0, 0, 1, 1]], np.eye(4))
      )
      hts = get_random_hts(S=S, periods=PERIODS, freq=FREQ)
  
      num_bottom_ts = S.shape[1]
      num_features = 10
      num_future_time_steps = {
          "train": 0,
          "inference": PERIODS // 2,
          "fail": PERIODS // 2,
      }[mode]
  
      features_df = random_ts(
          num_ts=num_features,
          periods=PERIODS + num_future_time_steps,
          freq=FREQ,
      )
  
      if mode == "fail":
          # Create a misalignment with the index of target time series.
          features_df.index = features_df.index.shift(periods=-1)
  
          with pytest.raises(Exception):
              ds = hts.to_dataset(feat_dynamic_real=features_df)
      else:
          ds = hts.to_dataset(feat_dynamic_real=features_df)
          entry = first(ds)
  
          assert entry["start"] == features_df.index[0]
  
          if mode == "train":
              entry["target"].shape == (num_bottom_ts, PERIODS)
              entry["feat_dynamic_real"].shape == (
                  num_features,
                  PERIODS,
              )
          else:
              entry["target"].shape == (
                  num_bottom_ts,
                  PERIODS + num_future_time_steps,
              )
              entry["feat_dynamic_real"].shape == (
                  num_features,
                  PERIODS + num_future_time_steps,
              )
  
file_path: gluonts/test/dataset/test_hierarchical.py
imports: import numpy
  import pandas
  from toolz.itertoolz import first
  import pytest
  from gluonts.dataset.hierarchical import HierarchicalTimeSeries
label_desc: Use image node_id 4 for calling a global function with example usage: test_hts_to_dataset(mode) without return types