code: def createBranch(
      config: dict,
      current_class: str,
      subdataset: pd.DataFrame,
      numericColumn: bool,
      branch_index: int,
      winner_name: str,
      winner_index: int,
      root: int,
      parents: str,
      file: str,
      dataset_features: dict,
      num_of_instances: int,
      metric: float,
      tree_id: int = 0,
      main_process_id: Optional[int] = None,
  ) -> list:
      """
      Create a branch and its leafs in the tree
      Args:
          config (dict): training configuration
          current_class (str): condition for the current leaf
              e.g. '>40' or '<=40' if the current branch is age
          subdataset (pd.DataFrame): filtered dataframe for the
              current_class' condition
          numericColumn (bool): current branch is numeric or nominal
          branch_index (int): current index. will use if for the first
              one and elif for the rest
          winner_name (str): the most dominant feature's name
          winner_index (int): index of the most dominant feature's name
          root (int): depth of the current decision rule
          parents (str): parent's uuid. using root name for the top one.
          file (str): target file to store rules
          dataset_features (dict): feature names
          num_of_instances (int): number of rows
          metric (float): e.g. information gain result for ID3
          tree_id (int): current tree's id
          main_process_id (int): main tree's process id
      Returns
          custom rules (list)
      """
      custom_rules = []
  
      algorithm = config["algorithm"]
      enableAdaboost = config["enableAdaboost"]
      enableGBM = config["enableGBM"]
      max_depth = config["max_depth"]
      enableParallelism = config["enableParallelism"]
  
      charForResp = "'"
      if algorithm == "Regression":
          charForResp = ""
  
      # ---------------------------
  
      tmp_root = root * 1
      parents_raw = copy.copy(parents)
  
      # ---------------------------
  
      if numericColumn == True:
          compareTo = current_class  # current class might be <=x or >x in this case
      else:
          compareTo = " == '" + str(current_class) + "'"
  
      terminateBuilding = False
  
      # -----------------------------------------------
      # can decision be made?
  
      if enableGBM == True and root >= max_depth:  # max depth
          final_decision = subdataset["Decision"].mean()
          terminateBuilding = True
      elif enableAdaboost == True:
          # final_decision = subdataset['Decision'].value_counts().idxmax()
          final_decision = functions.sign(
              subdataset["Decision"].mean()
          )  # get average
          terminateBuilding = True
          enableParallelism = False
      elif len(subdataset["Decision"].value_counts().tolist()) == 1:
          final_decision = (
              subdataset["Decision"].value_counts().keys().tolist()[0]
          )  # all items are equal in this case
          terminateBuilding = True
      elif (
          subdataset.shape[1] == 1
      ):  # if decision cannot be made even though all columns dropped
          final_decision = (
              subdataset["Decision"].value_counts().idxmax()
          )  # get the most frequent one
          terminateBuilding = True
      elif algorithm == "Regression" and (
          subdataset.shape[0] < 5 or root >= max_depth
      ):  # pruning condition
          final_decision = subdataset["Decision"].mean()  # get average
          terminateBuilding = True
      elif (
          algorithm in ["ID3", "C4.5", "CART", "CHAID"]
          and root >= max_depth
      ):
          final_decision = (
              subdataset["Decision"].value_counts().idxmax()
          )  # get the most frequent one
          terminateBuilding = True
  
      # -----------------------------------------------
  
      if enableParallelism == True:
          check_condition = "if"  # TODO: elif checks might be above than if statements in parallel
      else:
          if branch_index == 0:
              check_condition = "if"
          else:
              check_condition = "elif"
  
      check_rule = (
          check_condition
          + " obj["
          + str(winner_index)
          + "]"
          + compareTo
          + ":"
      )
  
      leaf_id = str(uuid.uuid1())
  
      if enableParallelism != True:
          functions.storeRule(
              file, (functions.formatRule(root), "", check_rule)
          )
      else:
          sample_rule = {}
          sample_rule["current_level"] = root
          sample_rule["leaf_id"] = leaf_id
          sample_rule["parents"] = parents
          sample_rule["rule"] = check_rule
          sample_rule["feature_idx"] = winner_index
          sample_rule["feature_name"] = winner_name
          sample_rule["instances"] = num_of_instances
          sample_rule["metric"] = metric
          sample_rule["return_statement"] = 0
          sample_rule["tree_id"] = tree_id
  
          # json to string
          sample_rule = json.dumps(sample_rule)
  
          custom_rules.append(sample_rule)
  
      # -----------------------------------------------
  
      if terminateBuilding == True:  # check decision is made
          parents = copy.copy(leaf_id)
          leaf_id = str(uuid.uuid1())
  
          decision_rule = (
              "return "
              + charForResp
              + str(final_decision)
              + charForResp
          )
  
          if enableParallelism != True:
              # serial
              functions.storeRule(
                  file, (functions.formatRule(root + 1), decision_rule)
              )
          else:
              # parallel
              sample_rule = {}
              sample_rule["current_level"] = root + 1
              sample_rule["leaf_id"] = leaf_id
              sample_rule["parents"] = parents
              sample_rule["rule"] = decision_rule
              sample_rule["feature_idx"] = winner_index
              sample_rule["feature_name"] = winner_name
              sample_rule["instances"] = num_of_instances
              sample_rule["metric"] = 0
              sample_rule["return_statement"] = 1
              sample_rule["tree_id"] = tree_id
  
              # json to string
              sample_rule = json.dumps(sample_rule)
  
              custom_rules.append(sample_rule)
  
      else:  # decision is not made, continue to create branch and leafs
          root = (
              root + 1
          )  # the following rule will be included by this rule. increase root
          parents = copy.copy(leaf_id)
  
          results = buildDecisionTree(
              subdataset,
              root,
              file,
              config,
              dataset_features,
              root - 1,
              leaf_id,
              parents,
              tree_id=tree_id,
              main_process_id=main_process_id,
          )
  
          custom_rules = custom_rules + results
  
          root = tmp_root * 1
          parents = copy.copy(parents_raw)
  
      gc.collect()
  
      return custom_rules
  
imports: import math
  import uuid
  import json
  import copy
  import gc
  from contextlib import closing
  from typing import Optional
  import psutil
  import numpy
  import pandas
  from chefboost.training import Preprocess
  from chefboost.commons import functions
  from chefboost.commons.logger import Logger
  from chefboost.commons.module import load_module
  from chefboost.commons.daemon import CustomPool
label_desc: Use image node_id 5 for calling a global function with example usage: createBranch(config, current_class, subdataset, numericColumn, branch_index, winner_name, winner_index, root, parents, file, dataset_features, num_of_instances, metric, tree_id, main_process_id) and returns: custom_rules