

@utils.allow_tableset_proxy
def order_by(self, key, reverse=False):
    '\n    Create a new table that is sorted.\n\n    :param key:\n        Either the name of a single column to sort by, a sequence of such\n        names, or a :class:`function` that takes a row and returns a value\n        to sort by.\n    :param reverse:\n        If `True` then sort in reverse (typically, descending) order.\n    :returns:\n        A new :class:`.Table`.\n    '
    if (len(self._rows) == 0):
        return self._fork(self._rows)
    else:
        key_is_row_function = hasattr(key, '__call__')
        key_is_sequence = utils.issequence(key)

        def sort_key(data):
            row = data[1]
            if key_is_row_function:
                k = key(row)
            elif key_is_sequence:
                k = tuple((row[n] for n in key))
            else:
                k = row[key]
            if (k is None):
                return utils.NullOrder()
            return k
        results = sorted(enumerate(self._rows), key=sort_key, reverse=reverse)
        (indices, rows) = zip(*results)
        if (self._row_names is not None):
            row_names = [self._row_names[i] for i in indices]
        else:
            row_names = None
        return self._fork(rows, row_names=row_names)

dataset/ETHPy150Open wireservice/agate/agate/table/order_by.py order_by/original