code: def to_time_series_dataset(dataset, dtype=float, be=None):
      """Transforms a time series dataset so that it fits the format used in
      ``tslearn`` models.
  
      Parameters
      ----------
      dataset : array-like, shape=(n_ts, sz, d) or (n_ts, sz) or (sz,)
          The dataset of time series to be transformed. A single time series will
          be automatically wrapped into a dataset with a single entry.
      dtype : data type (default: float)
          Data type for the returned dataset.
  
      Returns
      -------
      dataset_out : array-like, shape=(n_ts, sz, d)
          The transformed dataset of time series.
  
      Examples
      --------
      >>> to_time_series_dataset([[1, 2]])
      array([[[1.],
              [2.]]])
      >>> to_time_series_dataset([1, 2])
      array([[[1.],
              [2.]]])
      >>> to_time_series_dataset([[1, 2], [1, 4, 3]])
      array([[[ 1.],
              [ 2.],
              [nan]],
      <BLANKLINE>
             [[ 1.],
              [ 4.],
              [ 3.]]])
      >>> to_time_series_dataset([]).shape
      (0, 0, 0)
  
      See Also
      --------
      to_time_series : Transforms a single time series
      """
      be = instantiate_backend(be, dataset)
  
      try:
          import pandas as pd
  
          if isinstance(dataset, pd.DataFrame):
              return to_time_series_dataset(be.array(dataset), be=be)
      except ImportError:
          pass
      if isinstance(dataset, NotAnArray):  # Patch to pass sklearn tests
          return to_time_series_dataset(be.array(dataset), be=be)
      if len(dataset) == 0:
          return be.zeros((0, 0, 0))
      if be.ndim(be.array(dataset[0])) == 0:
          dataset = [dataset]
      n_ts = len(dataset)
      max_sz = max(
          [
              ts_size(to_time_series(ts, remove_nans=True, be=be))
              for ts in dataset
          ]
      )
      d = be.shape(to_time_series(dataset[0], be=be))[1]
      dataset_out = be.zeros((n_ts, max_sz, d), dtype=dtype) + be.nan
      for i in range(n_ts):
          ts = to_time_series(dataset[i], remove_nans=True, be=be)
          dataset_out[i, : ts.shape[0]] = ts
      return be.cast(dataset_out, dtype=dtype)
  
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 3 for calling a global function with example usage: to_time_series_dataset(dataset, dtype, be) and returns: be, to_time_series_dataset, be, to_time_series_dataset