code: def parse_cats(X, cats, sep: str = "_"):
      """parse onehot encoded columns to a onehot_dict.
      - cats can be a dict where you enumerate each individual onehot encoded column belonging to
          each categorical feature, e.g. cats={
                      'Sex':['Sex_female', 'Sex_male'],
                      'Deck':['Deck_A', 'Deck_B', 'Deck_C', 'Deck_nan']
                      }
      - if you encode your categorical features as Cat_Label, you can pass a list of the
          original feature names: cats=["Sex", "Deck"]
      - or a combination of the two: cats = ["Sex", {'Deck':['Deck_A', 'Deck_B', 'Deck_C', 'Deck_nan']}]
  
      Asserts that all columns can be found in X.columns.
      Asserts that all columns are only passed once.
      """
      all_cols = X.columns
      onehot_cols = []
      onehot_dict = {}
  
      col_counter = Counter()
  
      if isinstance(cats, dict):
          for k, v in cats.items():
              assert set(v).issubset(
                  set(all_cols)
              ), f"These cats columns for {k} could not be found in X.columns: {set(v)-set(all_cols)}!"
              col_counter.update(v)
          onehot_dict = cats
      elif isinstance(cats, list):
          for cat in cats:
              if isinstance(cat, str):
                  onehot_dict[cat] = [
                      c for c in all_cols if c.startswith(cat + sep)
                  ]
                  col_counter.update(onehot_dict[cat])
              if isinstance(cat, dict):
                  for k, v in cat.items():
                      assert set(v).issubset(
                          set(all_cols)
                      ), f"These cats columns for {k} could not be found in X.columns: {set(v)-set(all_cols)}!"
                      col_counter.update(v)
                      onehot_dict[k] = v
      multi_cols = [v for v, c in col_counter.most_common() if c > 1]
      assert not multi_cols, (
          f"The following columns seem to have been passed to cats multiple times: {multi_cols}. "
          "Please make sure that each onehot encoded column is only assigned to one cat column!"
      )
      assert not set(onehot_dict.keys()) & set(all_cols), (
          f"These new cats columns are already in X.columns: {list(set(onehot_dict.keys()) & set(all_cols))}! "
          "Please select a different name for your new cats columns!"
      )
      for col, count in col_counter.most_common():
          assert set(X[col].astype(int).unique()).issubset(
              {0, 1}
          ), f"{col} is not a onehot encoded column (i.e. has values other than 0, 1)!"
      onehot_cols = list(onehot_dict.keys())
      for col in [
          col for col in all_cols if col not in col_counter.keys()
      ]:
          onehot_dict[col] = [col]
      return onehot_cols, onehot_dict
  
imports: from functools import partial
  import re
  from collections import Counter
  from typing import List, Union
  import warnings
  import numpy
  import pandas
  from pandas.api.types import is_numeric_dtype, is_categorical_dtype
  from dtreeviz.trees import ShadowDecTree
  from sklearn.metrics import make_scorer
  from sklearn.base import clone
  from sklearn.pipeline import Pipeline
  from sklearn.model_selection import KFold, StratifiedKFold
  from joblib import Parallel, delayed
label_desc: Use image node_id 5 for calling a global function with example usage: parse_cats(X, cats, sep) and returns: onehot_cols,  onehot_dict