code: def test_from_multiindex_to_listdataset(
      n_instances, n_columns, n_timepoints
  ):
      """Test from multiindex DF to listdataset for gluonts."""
      import numpy as np
      import pandas as pd
  
      from sktime.datatypes import convert_to
  
      # from sktime.datatypes._adapters import convert_from_multiindex_to_listdataset
  
      def random_datetimes_or_dates(
          start, end, out_format="datetime", n=10, random_seed=42
      ):
          """Generate random pd Datetime in the start to end range.
  
          unix timestamp is in ns by default. Divide the unix time value by 10**9 to make
          it seconds (or 24*60*60*10**9 to make it days). The corresponding unit variable
          is passed to the pd.to_datetime function. Values for the (divide_by, unit) pair
          to select is defined by the out_format parameter. for 1 -> out_format='datetime'
          for 2 -> out_format=anything else.
          """
          np.random.seed(random_seed)
          (divide_by, unit) = (
              (10**9, "s")
              if out_format == "datetime"
              else (24 * 60 * 60 * 10**9, "D")
          )
  
          start_u = start.value // divide_by
          end_u = end.value // divide_by
  
          return pd.to_datetime(
              np.random.randint(start_u, end_u, n), unit=unit
          )
  
      def _make_example_multiindex(
          n_instances, n_columns, n_timepoints, random_seed=42
      ) -> pd.DataFrame:
          import numpy as np
  
          start = pd.to_datetime("1750-01-01")
          end = pd.to_datetime("2022-07-01")
          inputDF = np.random.randint(
              1, 99, size=(n_instances * n_timepoints, n_columns)
          )
          n_instances = n_instances
          column_name = []
          for i in range(n_columns):
              column_name.append("dim_" + str(i))
  
          random_start_date = random_datetimes_or_dates(
              start,
              end,
              out_format="out datetime",
              n=n_instances,
              random_seed=42,
          )
  
          level0_idx = [
              list(np.full(n_timepoints, instance))
              for instance in range(n_instances)
          ]
          level0_idx = np.ravel(level0_idx)
  
          level1_idx = [
              list(
                  pd.date_range(
                      random_start_date[instance],
                      periods=n_timepoints,
                      freq="H",
                  )
              )
              for instance in range(n_instances)
          ]
          level1_idx = np.ravel(level1_idx)
  
          multi_idx = pd.MultiIndex.from_arrays(
              [level0_idx, level1_idx], names=("instance", "datetime")
          )
  
          inputDF_return = pd.DataFrame(
              inputDF, columns=column_name, index=multi_idx
          )
  
          return inputDF_return
  
      MULTIINDEX_DF = _make_example_multiindex(
          n_instances, n_columns, n_timepoints
      )
      # Result from the converter
      listdataset_result = convert_from_multiindex_to_listdataset(
          MULTIINDEX_DF
      )
      listdataset_result_list = list(listdataset_result)
      # Result from raw data
      dimension_name = MULTIINDEX_DF.columns
      # Convert MULTIINDEX_DF to nested_univ format to compare with listdataset
      control_result = convert_to(MULTIINDEX_DF, to_type="nested_univ")
      control_result = control_result.reset_index()
      control_result = control_result[dimension_name]
  
      # Perform the test
      for instance, _dim_name in control_result.iterrows():
          for dim_no, dim in enumerate(dimension_name):
              np.testing.assert_array_equal(
                  control_result.loc[instance, dim].to_numpy(),
                  listdataset_result_list[instance]["target"][dim_no],
              )
  
imports: import numpy
  import pandas
  import pytest
  from sktime.datasets import generate_example_long_table, make_multi_index_dataframe
  from sktime.datatypes._adapter import convert_from_multiindex_to_listdataset
  from sktime.datatypes._panel._check import are_columns_nested, is_nested_dataframe
  from sktime.datatypes._panel._convert import from_2d_array_to_nested, from_3d_numpy_to_2d_array, from_3d_numpy_to_multi_index, from_3d_numpy_to_nested, from_long_to_nested, from_multi_index_to_3d_numpy, from_multi_index_to_nested, from_nested_to_2d_array, from_nested_to_3d_numpy, from_nested_to_long, from_nested_to_multi_index
  from sktime.utils._testing.panel import make_classification_problem
  from sktime.utils.validation._dependencies import _check_soft_dependencies
label_desc: Use image node_id 14 for calling a global function with example usage: test_from_multiindex_to_listdataset(n_instances, n_columns, n_timepoints) and returns: pd, inputDF_return