code: def to_time_series(ts, remove_nans=False, be=None):
      """Transforms a time series so that it fits the format used in ``tslearn``
      models.
  
      Parameters
      ----------
      ts : array-like, shape=(sz, d) or (sz,)
          The time series to be transformed.
          If shape is (sz,), the time series is assumed to be univariate.
      remove_nans : bool (default: False)
          Whether trailing NaNs at the end of the time series should be removed
          or not
      be : Backend object or string or None
          Backend. If `be` is an instance of the class `NumPyBackend` or the string `"numpy"`,
          the NumPy backend is used.
          If `be` is an instance of the class `PyTorchBackend` or the string `"pytorch"`,
          the PyTorch backend is used.
          If `be` is `None`, the backend is determined by the input arrays.
          See our :ref:`dedicated user-guide page <backend>` for more information.
  
      Returns
      -------
      ts_out : array-like, shape=(sz, d)
          The transformed time series. This is always guaraneteed to be a new
          time series and never just a view into the old one.
  
      Examples
      --------
      >>> to_time_series([1, 2])
      array([[1.],
             [2.]])
      >>> to_time_series([1, 2, numpy.nan])
      array([[ 1.],
             [ 2.],
             [nan]])
      >>> to_time_series([1, 2, numpy.nan], remove_nans=True)
      array([[1.],
             [2.]])
  
      See Also
      --------
      to_time_series_dataset : Transforms a dataset of time series
      """
      be = instantiate_backend(be, ts)
      ts_out = be.array(ts)
      if ts_out.ndim <= 1:
          ts_out = be.reshape(ts_out, (-1, 1))
      if not be.is_float(ts_out):
          ts_out = be.cast(ts_out, dtype=float)
      if remove_nans:
          ts_out = ts_out[: ts_size(ts_out, be=be)]
      return ts_out
  
imports: import warnings
  from io import StringIO
  import numpy
  from sklearn.base import TransformerMixin
  from sklearn.utils import column_or_1d
  from sklearn.utils.validation import check_is_fitted
  from tslearn.backend import instantiate_backend
  from tslearn.bases import TimeSeriesBaseEstimator
label_desc: Use image node_id 2 for calling a global function with example usage: to_time_series(ts, remove_nans, be) and returns: ts_out