nodes: 0, module; 1, function_definition; 2, function_name:as_index; 3, parameters; 4, block; 5, identifier:keys; 6, default_parameter; 7, default_parameter; 8, default_parameter; 9, default_parameter; 10, expression_statement; 11, if_statement; 12, if_statement; 13, try_statement; 14, if_statement; 15, if_statement; 16, identifier:axis; 17, attribute; 18, identifier:base; 19, False; 20, identifier:stable; 21, True; 22, identifier:lex_as_struct; 23, False; 24, comment:"""
      casting rules for a keys object to an index object
  
      the preferred semantics is that keys is a sequence of key objects,
      except when keys is an instance of tuple,
      in which case the zipped elements of the tuple are the key objects
  
      the axis keyword specifies the axis which enumerates the keys
      if axis is None, the keys array is flattened
      if axis is 0, the first axis enumerates the keys
      which of these two is the default depends on whether backwards_compatible == True
  
      if base==True, the most basic index possible is constructed.
      this avoids an indirect sort; if it isnt required, this has better performance
      """; 25, call; 26, block; 27, call; 28, block; 29, block; 30, except_clause; 31, comparison_operator:axis is None; 32, block; 33, comparison_operator:keys.ndim==1; 34, block; 35, else_clause; 36, identifier:semantics; 37, identifier:axis_default; 38, identifier:isinstance; 39, argument_list; 40, if_statement; 41, identifier:isinstance; 42, argument_list; 43, if_statement; 44, expression_statement; 45, block; 46, identifier:axis; 47, None; 48, expression_statement; 49, attribute; 50, integer:1; 51, if_statement; 52, block; 53, identifier:keys; 54, identifier:Index; 55, boolean_operator; 56, block; 57, else_clause; 58, identifier:keys; 59, identifier:tuple; 60, identifier:lex_as_struct; 61, block; 62, else_clause; 63, assignment; 64, raise_statement; 65, assignment; 66, identifier:keys; 67, identifier:ndim; 68, identifier:base; 69, block; 70, else_clause; 71, return_statement; 72, comparison_operator:type(keys) is BaseIndex; 73, comparison_operator:base==False; 74, expression_statement; 75, comment:#need to upcast to an indirectly sorted index type; 76, block; 77, expression_statement; 78, block; 79, identifier:keys; 80, call; 81, call; 82, identifier:keys; 83, call; 84, return_statement; 85, block; 86, call; 87, call; 88, identifier:BaseIndex; 89, identifier:base; 90, False; 91, assignment; 92, return_statement; 93, comment:#already done here; 94, assignment; 95, return_statement; 96, attribute; 97, argument_list; 98, identifier:TypeError; 99, argument_list; 100, attribute; 101, argument_list; 102, call; 103, return_statement; 104, identifier:ObjectIndex; 105, argument_list; 106, identifier:type; 107, argument_list; 108, identifier:keys; 109, attribute; 110, identifier:keys; 111, identifier:keys; 112, call; 113, call; 114, identifier:np; 115, identifier:asarray; 116, identifier:keys; 117, string; 118, identifier:keys; 119, identifier:flatten; 120, identifier:BaseIndex; 121, argument_list; 122, call; 123, identifier:keys; 124, identifier:axis; 125, keyword_argument; 126, identifier:keys; 127, identifier:keys; 128, identifier:keys; 129, identifier:as_struct_array; 130, argument_list; 131, identifier:LexIndex; 132, argument_list; 133, string_content:Given object does not form a valid set of keys; 134, identifier:keys; 135, identifier:Index; 136, argument_list; 137, identifier:stable; 138, identifier:stable; 139, list_splat; 140, identifier:keys; 141, identifier:stable; 142, identifier:keys; 143, keyword_argument; 144, identifier:keys; 145, identifier:stable; 146, identifier:stable
code: def as_index(keys, axis=semantics.axis_default, base=False, stable=True, lex_as_struct=False):
      """
      casting rules for a keys object to an index object
  
      the preferred semantics is that keys is a sequence of key objects,
      except when keys is an instance of tuple,
      in which case the zipped elements of the tuple are the key objects
  
      the axis keyword specifies the axis which enumerates the keys
      if axis is None, the keys array is flattened
      if axis is 0, the first axis enumerates the keys
      which of these two is the default depends on whether backwards_compatible == True
  
      if base==True, the most basic index possible is constructed.
      this avoids an indirect sort; if it isnt required, this has better performance
      """
      if isinstance(keys, Index):
          if type(keys) is BaseIndex and base==False:
              keys = keys.keys    #need to upcast to an indirectly sorted index type
          else:
              return keys         #already done here
      if isinstance(keys, tuple):
          if lex_as_struct:
              keys = as_struct_array(*keys)
          else:
              return LexIndex(keys, stable)
  
      try:
          keys = np.asarray(keys)
      except:
          raise TypeError('Given object does not form a valid set of keys')
      if axis is None:
          keys = keys.flatten()
      if keys.ndim==1:
          if base:
              return BaseIndex(keys)
          else:
              return Index(keys, stable=stable)
      else:
          return ObjectIndex(keys, axis, stable=stable)