code: def load_from_tsfile(
      full_file_path_and_name,
      replace_missing_vals_with="NaN",
      return_y=True,
      return_data_type="nested_univ",
  ):
      """Load time series .ts file into X and (optionally) y.
  
      Data from a .ts file is loaded into a nested pd.DataFrame, or optionally into a
      2d np.ndarray (equal length, univariate problem) or 3d np.ndarray (equal length,
      multivariate problem) if requested. If present, y is loaded into a 1d np.ndarray.
  
      Parameters
      ----------
      full_file_path_and_name : str
          The full pathname and file name of the .ts file to read.
      replace_missing_vals_with : str, default NaN
         The value that missing values in the text file should be replaced with prior
         to parsing.
      return_y : boolean, default True
         whether to return the y variable, if it is present.
      return_data_type : str, optional, default = "nested_univ"
          memory data format specification to return X in.
          str can be any other supported Panel mtype
              for list of mtypes, see datatypes.SCITYPE_REGISTER
              for specifications, see examples/AA_datatypes_and_datasets.ipynb
          commonly used specifications:
              "nested_univ: nested pd.DataFrame, pd.Series in cells
              "numpy3D"/"numpy3d"/"np3D": 3D np.ndarray (instance, variable, time index)
              "numpy2d"/"np2d"/"numpyflat": 2D np.ndarray (instance, time index)
              "pd-multiindex": pd.DataFrame with 2-level (instance, time) MultiIndex
          Exception is raised if the data cannot be stored in the requested type.
  
      Returns
      -------
      X : sktime compatible in-memory container of mtype return_data_type
          for list of mtypes, see datatypes.SCITYPE_REGISTER
          for specifications, see examples/AA_datatypes_and_datasets.ipynb
      y : returned only if return_y=True, np.ndarray
  
      Raises
      ------
      IOError if the requested file does not exist
      IOError if input series are not all the same dimension (not supported)
      IOError if class labels have been requested but are not present in the file
      IOError if the input file has no cases
      ValueError if return_data_type = numpy3d but the data are unequal length series
      ValueError if return_data_type = numpy2d but the data are multivariate and/
      or unequal length series
      """
      return_data_type = _alias_mtype_check(return_data_type)
  
      if not isinstance(return_data_type, str):
          raise TypeError(
              f"return_data_type argument must be a str, but found "
              f"{type(return_data_type)}"
          )
      if return_data_type not in MTYPE_LIST_PANEL:
          raise ValueError(
              f"return_data_type must be one of the following identifier strings for "
              f"sktime panel time series data format specifications: {MTYPE_LIST_PANEL}, "
              f"but found {return_data_type}"
          )
  
      # Initialize flags and variables used when parsing the file
      X, y = load_from_tsfile_to_dataframe(
          full_file_path_and_name=full_file_path_and_name,
          return_separate_X_and_y=True,
          replace_missing_vals_with=replace_missing_vals_with,
      )
  
      X = convert(X, from_type="nested_univ", to_type=return_data_type)
  
      if return_y:
          return X, y
      else:
          return X
  
file_path: sktime/sktime/datasets/_readers_writers/ts.py
imports: import itertools
  import numpy
  import pandas
  from sktime.datasets._readers_writers.utils import _alias_mtype_check, _write_header
  from sktime.datatypes import MTYPE_LIST_PANEL, check_is_scitype, convert, convert_to
  from sktime.utils.validation.panel import check_X, check_X_y
label_desc: Use image node_id 2 for calling a global function with example usage: load_from_tsfile(full_file_path_and_name, replace_missing_vals_with, return_y, return_data_type) and returns: X,  y, X