code: def load_datasets(
      metadata: Path,
      train: Path,
      test: Optional[Path],
      one_dim_target: bool = True,
      cache: bool = False,
  ) -> TrainDatasets:
      """
      Loads a dataset given metadata, train and test path.
  
      Parameters
      ----------
      metadata
          Path to the metadata file
      train
          Path to the training dataset files.
      test
          Path to the test dataset files.
      one_dim_target
          Whether to load FileDatasets as univariate target time series.
      cache
          Indicates whether the FileDatasets should be cached or not.
  
      Returns
      -------
      TrainDatasets
          An object collecting metadata, training data, test data.
      """
      meta = MetaData.parse_file(Path(metadata) / "metadata.json")
      train_ds = FileDataset(
          path=train,
          freq=meta.freq,
          one_dim_target=one_dim_target,
          cache=cache,
      )
      test_ds = (
          FileDataset(
              path=test,
              freq=meta.freq,
              one_dim_target=one_dim_target,
              cache=cache,
          )
          if test
          else None
      )
  
      return TrainDatasets(metadata=meta, train=train_ds, test=test_ds)
  
imports: import functools
  import logging
  import shutil
  from pathlib import Path
  from types import ModuleType
  from typing import Callable, List, NamedTuple, Optional, Union, cast
  import numpy
  import pandas
  from pandas.tseries.frequencies import to_offset
  from gluonts import json
  from gluonts.itertools import Cached, Map
  from gluonts.dataset.field_names import FieldName
  from gluonts.dataset.schema import Translator
  from gluonts.exceptions import GluonTSDataError
  from gluonts.pydantic import pydantic
  from .None import Dataset, DatasetCollection, DataEntry, DataBatch
  from .None import jsonl, DatasetWriter
label_desc: Use image node_id 7 for calling a global function with example usage: load_datasets(metadata, train, test, one_dim_target, cache) and returns: TrainDatasets