code: def _flatten_single_indexes(X):
      """Check the index of X and return new unique index object."""
      # get unique indexes outwith timepoints
      inds = list(X.droplevel(-1).index.unique())
      ind_df = pd.DataFrame(inds)
  
      # add the new top aggregate level
      if len(ind_df.columns) == 1:
          out_list = ["__total"]
      else:
          out_list = [tuple(np.repeat("__total", len(ind_df.columns)))]
  
          # for each level check there are child nodes of length >1
          for i in range(1, len(ind_df.columns)):
              # all levels from top
              ind_aggs = ind_df.loc[:, ind_df.columns[0:-i:]]
              # filter and check for child nodes with only 1 nunique name
              if len(ind_aggs.columns) > 1:
                  filter_cols = list(ind_aggs.columns[0:-1])
                  filter_inds = ind_aggs.groupby(
                      by=filter_cols, as_index=False
                  ).transform(lambda x: x.nunique())
                  filter_inds = (
                      filter_inds[(filter_inds > 1)].dropna().index
                  )
                  ind_aggs = ind_aggs.iloc[filter_inds, :]
              else:
                  pass
  
              tmp = ind_aggs.groupby(by=list(ind_aggs.columns)).size()
  
              # get idex of these nodes
              agg_ids = list(tmp[tmp > 1].dropna().index)
  
              # add the aggregate label down the the length of the original index
  
              # only add if >=1 elements in list and not at the 2nd aggregate level
              add_indicator1 = (i < (len(ind_df.columns) - 1)) & (
                  len(agg_ids) >= 1
              )
              # or at the second most aggregate level and there are two aggs to add
              # or at the second most aggregate level and there is 1 agg to add,
              #   but the top level has more than one unique index
              add_indicator2 = (len(agg_ids) > 1) | (
                  (len(agg_ids) == 1)
                  & (ind_df.iloc[:, 0].nunique() > 1)
              )
  
              if add_indicator1 | add_indicator2:
                  agg_ids = [
                      tuple([x]) if type(x) is not tuple else x
                      for x in agg_ids
                  ]
                  for _j in range(i):
                      agg_ids = [x + ("__total",) for x in agg_ids]
  
                  out_list.extend(agg_ids)
              else:
                  pass
  
      # add to original index
      inds.extend(out_list)
  
      if len(ind_df.columns) == 1:
          new_index = pd.Index(inds, name=X.index.droplevel(-1).name)
      else:
          new_index = pd.MultiIndex.from_tuples(
              inds,
              names=X.index.droplevel(-1).names,
          )
  
      return new_index
  
file_path: sktime/sktime/transformations/hierarchical/aggregate.py
imports: import numpy
  import pandas
  from sktime.transformations.base import BaseTransformer
  from sktime.utils.warnings import warn
label_desc: Use image node_id 2 for calling a global function with example usage: _flatten_single_indexes(X) and returns: new_index