code: def multiindex_from_product_levels(levels: Sequence[pd.Index],
                                     names: Optional[Sequence[str]] = None
                                     ) -> pd.MultiIndex:
      
      if any(not isinstance(lev, pd.Index) for lev in levels):
          raise TypeError('levels must be a list of pd.Index objects')
  
      split_labels, levels = zip(*[lev.factorize() for lev in levels])
      labels_mesh = np.meshgrid(*split_labels, indexing='ij')
      labels = [x.ravel() for x in labels_mesh]
      return pd.MultiIndex(levels, labels, sortorder=0, names=names)
docs: Creating a MultiIndex from a product without refactorizing levels.
  
      Keeping levels the same gives back the original labels when we unstack.
  
      Parameters
      ----------
      levels : sequence of pd.Index
          Values for each MultiIndex level.
      names : optional sequence of objects
          Names for each level.
  
      Returns
      -------
      pandas.MultiIndex