nodes: 0, module; 1, function_definition; 2, function_name:get_multiplier; 3, parameters; 4, block; 5, identifier:weights; 6, identifier:root_generic_multiplier; 7, expression_statement; 8, if_statement; 9, expression_statement; 10, expression_statement; 11, for_statement; 12, expression_statement; 13, expression_statement; 14, return_statement; 15, comment:"""
      Determine tradeable instrument multiplier based on generic asset
      multipliers and weights mapping from generics to tradeables.
  
      Parameters
      ----------
      weights: pandas.DataFrame or dict
          A pandas.DataFrame of loadings of generic contracts on tradeable
          instruments **for a given date**. The columns are integers refering to
          generic number indexed from 0, e.g. [0, 1], and the index is strings
          representing instrument names. If dict is given keys should be generic
          instrument names, e.g. 'CL', and values should be pandas.DataFrames of
          loadings. The union of all indexes should be a superset of the
          instruments.index
      root_generic_multiplier: pandas.Series
          Series of multipliers for generic instruments lexigraphically sorted.
          If a dictionary of weights is given, root_generic_multiplier.index
          should correspond to the weights keys.
  
      Returns
      -------
      A pandas.Series of multipliers for tradeable instruments.
  
      Examples
      --------
      >>> import pandas as pd
      >>> import mapping.util as util
      >>> wts = pd.DataFrame([[0.5, 0], [0.5, 0.5], [0, 0.5]],
      ...                    index=["CLX16", "CLZ16", "CLF17"],
      ...                    columns=[0, 1])
      >>> ast_mult = pd.Series([1000], index=["CL"])
      >>> util.get_multiplier(wts, ast_mult)
      """; 16, boolean_operator; 17, block; 18, assignment; 19, assignment; 20, pattern_list; 21, call; 22, block; 23, assignment; 24, assignment; 25, identifier:imults; 26, comparison_operator:len(root_generic_multiplier) > 1; 27, not_operator; 28, raise_statement; 29, identifier:mults; 30, list; 31, identifier:intrs; 32, list; 33, identifier:ast; 34, identifier:multiplier; 35, attribute; 36, argument_list; 37, if_statement; 38, expression_statement; 39, expression_statement; 40, identifier:imults; 41, call; 42, identifier:imults; 43, call; 44, call; 45, integer:1; 46, call; 47, call; 48, identifier:root_generic_multiplier; 49, identifier:iteritems; 50, call; 51, block; 52, else_clause; 53, call; 54, call; 55, attribute; 56, argument_list; 57, attribute; 58, argument_list; 59, identifier:len; 60, argument_list; 61, identifier:isinstance; 62, argument_list; 63, identifier:ValueError; 64, argument_list; 65, identifier:isinstance; 66, argument_list; 67, expression_statement; 68, block; 69, attribute; 70, argument_list; 71, attribute; 72, argument_list; 73, identifier:pd; 74, identifier:Series; 75, identifier:mults; 76, identifier:intrs; 77, identifier:imults; 78, identifier:sort_index; 79, identifier:root_generic_multiplier; 80, identifier:weights; 81, identifier:dict; 82, concatenated_string; 83, identifier:weights; 84, identifier:dict; 85, assignment; 86, expression_statement; 87, identifier:mults; 88, identifier:extend; 89, call; 90, identifier:intrs; 91, identifier:extend; 92, identifier:weights_ast; 93, string:"For multiple generic instruments weights must be a "; 94, string:"dictionary"; 95, identifier:weights_ast; 96, attribute; 97, assignment; 98, attribute; 99, argument_list; 100, subscript; 101, identifier:index; 102, identifier:weights_ast; 103, attribute; 104, identifier:np; 105, identifier:repeat; 106, identifier:multiplier; 107, call; 108, identifier:weights; 109, identifier:ast; 110, identifier:weights; 111, identifier:index; 112, identifier:len; 113, argument_list; 114, identifier:weights_ast
code: def get_multiplier(weights, root_generic_multiplier):
      """
      Determine tradeable instrument multiplier based on generic asset
      multipliers and weights mapping from generics to tradeables.
  
      Parameters
      ----------
      weights: pandas.DataFrame or dict
          A pandas.DataFrame of loadings of generic contracts on tradeable
          instruments **for a given date**. The columns are integers refering to
          generic number indexed from 0, e.g. [0, 1], and the index is strings
          representing instrument names. If dict is given keys should be generic
          instrument names, e.g. 'CL', and values should be pandas.DataFrames of
          loadings. The union of all indexes should be a superset of the
          instruments.index
      root_generic_multiplier: pandas.Series
          Series of multipliers for generic instruments lexigraphically sorted.
          If a dictionary of weights is given, root_generic_multiplier.index
          should correspond to the weights keys.
  
      Returns
      -------
      A pandas.Series of multipliers for tradeable instruments.
  
      Examples
      --------
      >>> import pandas as pd
      >>> import mapping.util as util
      >>> wts = pd.DataFrame([[0.5, 0], [0.5, 0.5], [0, 0.5]],
      ...                    index=["CLX16", "CLZ16", "CLF17"],
      ...                    columns=[0, 1])
      >>> ast_mult = pd.Series([1000], index=["CL"])
      >>> util.get_multiplier(wts, ast_mult)
      """
      if len(root_generic_multiplier) > 1 and not isinstance(weights, dict):
          raise ValueError("For multiple generic instruments weights must be a "
                           "dictionary")
  
      mults = []
      intrs = []
      for ast, multiplier in root_generic_multiplier.iteritems():
          if isinstance(weights, dict):
              weights_ast = weights[ast].index
          else:
              weights_ast = weights.index
          mults.extend(np.repeat(multiplier, len(weights_ast)))
          intrs.extend(weights_ast)
  
      imults = pd.Series(mults, intrs)
      imults = imults.sort_index()
      return imults