Skip to content

Commit

Permalink
docs: improve docstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
lars-reimann committed Mar 27, 2023
1 parent 41c2f0c commit d1dc62e
Showing 1 changed file with 22 additions and 19 deletions.
41 changes: 22 additions & 19 deletions src/safeds/data/tabular/containers/_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -853,55 +853,58 @@ def slice(

def sort_columns(
self,
sorter: Callable[[Column, Column], int] =
comparator: Callable[[Column, Column], int] =
lambda col1, col2: (col1.name > col2.name) - (col1.name < col2.name),
) -> Table:
"""
Sort the columns of a `Table` with the given sorter and return a new `Table`. The original table is not
Sort the columns of a `Table` with the given comparator and return a new `Table`. The original table is not
modified.
The sorter is a function that takes two columns `col1` and `col2` and returns an integer. If `col1` should be
ordered before `col2`, the function should return a negative number. If `col1` should be ordered after `col2`,
the function should return a positive number. If the original order of `col1` and `col2` should be kept, the
function should return 0.
The comparator is a function that takes two columns `col1` and `col2` and returns an integer:
If no sorter is given, the columns will be sorted alphabetically by their name.
* If `col1` should be ordered before `col2`, the function should return a negative number.
* If `col1` should be ordered after `col2`, the function should return a positive number.
* If the original order of `col1` and `col2` should be kept, the function should return 0.
If no comparator is given, the columns will be sorted alphabetically by their name.
Parameters
----------
sorter : Callable[[Column, Column], int]
The function used to sort the columns.
comparator : Callable[[Column, Column], int]
The function used to compare two columns.
Returns
-------
new_table : Table
A new table with sorted columns.
"""
columns = self.to_columns()
columns.sort(key=functools.cmp_to_key(sorter))
columns.sort(key=functools.cmp_to_key(comparator))
return Table.from_columns(columns)

def sort_rows(self, sorter: Callable[[Row, Row], int]) -> Table:
def sort_rows(self, comparator: Callable[[Row, Row], int]) -> Table:
"""
Sort the rows of a `Table` with the given sorter and return a new `Table`. The original table is not modified.
Sort the rows of a `Table` with the given comparator and return a new `Table`. The original table is not
modified.
The comparator is a function that takes two rows `row1` and `row2` and returns an integer:
The sorter is a function that takes two rows `row1` and `row2` and returns an integer. If `row1` should be
ordered before `row2`, the function should return a negative number. If `row1` should be ordered after `row2`,
the function should return a positive number. If the original order of `row1` and `row2` should be kept, the
function should return 0.
* If `col1` should be ordered before `col2`, the function should return a negative number.
* If `col1` should be ordered after `col2`, the function should return a positive number.
* If the original order of `col1` and `col2` should be kept, the function should return 0.
Parameters
----------
sorter : Callable[[Row, Row], int]
The function used to sort the rows.
comparator : Callable[[Row, Row], int]
The function used to compare two rows.
Returns
-------
new_table : Table
A new table with sorted rows.
"""
rows = self.to_rows()
rows.sort(key=functools.cmp_to_key(sorter))
rows.sort(key=functools.cmp_to_key(comparator))
return Table.from_rows(rows)

def split(self, percentage_in_first: float) -> typing.Tuple[Table, Table]:
Expand Down

0 comments on commit d1dc62e

Please sign in to comment.