nodes: 0, module; 1, function_definition; 2, function_name:sort; 3, parameters; 4, block; 5, identifier:self; 6, identifier:fieldname; 7, default_parameter; 8, default_parameter; 9, default_parameter; 10, expression_statement; 11, try_statement; 12, expression_statement; 13, expression_statement; 14, for_statement; 15, comment:# Note that sorting in-place still returns a reference; 16, comment:# to the table being sorted, for convenience.; 17, return_statement; 18, identifier:key; 19, lambda; 20, identifier:desc; 21, False; 22, identifier:inplace; 23, False; 24, comment:"""
          This matches Python's built-in sorting signature closely.
  
          By default, a new DataTable will be returned and the original will
          not be mutated. If preferred, specify `inplace=True` in order to
          mutate the original table. Either way, a reference to the relevant
          table will be returned.
          """; 25, block; 26, except_clause; 27, assignment; 28, assignment; 29, pattern_list; 30, call; 31, block; 32, identifier:target_table; 33, lambda_parameters; 34, identifier:x; 35, expression_statement; 36, identifier:ValueError; 37, block; 38, identifier:data_cols; 39, call; 40, identifier:target_table; 41, conditional_expression:self if inplace else DataTable(); 42, identifier:field; 43, identifier:data_col; 44, identifier:izip; 45, argument_list; 46, expression_statement; 47, identifier:x; 48, assignment; 49, raise_statement; 50, identifier:izip; 51, argument_list; 52, identifier:self; 53, identifier:inplace; 54, call; 55, attribute; 56, identifier:data_cols; 57, assignment; 58, identifier:field_index; 59, call; 60, call; 61, list_splat; 62, identifier:DataTable; 63, argument_list; 64, identifier:self; 65, identifier:fields; 66, subscript; 67, call; 68, attribute; 69, argument_list; 70, identifier:ValueError; 71, argument_list; 72, call; 73, identifier:target_table; 74, identifier:field; 75, identifier:list; 76, argument_list; 77, call; 78, identifier:index; 79, identifier:fieldname; 80, binary_operator:"Sorting on a field that doesn't exist: `%s`" %
                               fieldname; 81, identifier:sorted; 82, argument_list; 83, identifier:data_col; 84, identifier:tuple; 85, argument_list; 86, string:"Sorting on a field that doesn't exist: `%s`"; 87, identifier:fieldname; 88, call; 89, keyword_argument; 90, keyword_argument; 91, attribute; 92, identifier:izip; 93, argument_list; 94, identifier:key; 95, lambda; 96, identifier:reverse; 97, identifier:desc; 98, identifier:self; 99, identifier:fields; 100, list_splat; 101, lambda_parameters; 102, call; 103, list_comprehension; 104, identifier:row; 105, identifier:key; 106, argument_list; 107, subscript; 108, for_in_clause; 109, subscript; 110, attribute; 111, identifier:field; 112, identifier:field; 113, attribute; 114, identifier:row; 115, identifier:field_index; 116, identifier:self; 117, identifier:__data; 118, identifier:self; 119, identifier:fields
code: def sort(self, fieldname, key=lambda x: x, desc=False, inplace=False):
          """
          This matches Python's built-in sorting signature closely.
  
          By default, a new DataTable will be returned and the original will
          not be mutated. If preferred, specify `inplace=True` in order to
          mutate the original table. Either way, a reference to the relevant
          table will be returned.
          """
          try:
              field_index = tuple(self.fields).index(fieldname)
          except ValueError:
              raise ValueError("Sorting on a field that doesn't exist: `%s`" %
                               fieldname)
  
          data_cols = izip(*sorted(izip(*[self.__data[field]
                                          for field in self.fields]),
                                   key=lambda row: key(row[field_index]),
                                   reverse=desc))
  
          target_table = self if inplace else DataTable()
  
          for field, data_col in izip(self.fields, data_cols):
              target_table[field] = list(data_col)
  
          # Note that sorting in-place still returns a reference
          # to the table being sorted, for convenience.
          return target_table