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 May 17, 2024
1 parent 712e925 commit b94a55e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 9 deletions.
13 changes: 5 additions & 8 deletions src/safeds/data/tabular/containers/_column.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
ColumnLengthMismatchError,
IndexOutOfBoundsError,
MissingValuesColumnError,
NonNumericColumnError,
)

from ._lazy_cell import _LazyCell
Expand Down Expand Up @@ -224,7 +223,7 @@ def get_distinct_values(

def get_value(self, index: int) -> T_co:
"""
Return the column value at specified index.
Return the column value at specified index. Equivalent to the `[]` operator (indexed access).
Nonnegative indices are counted from the beginning (starting at 0), negative indices from the end (starting at
-1).
Expand All @@ -250,6 +249,9 @@ def get_value(self, index: int) -> T_co:
>>> column = Column("test", [1, 2, 3])
>>> column.get_value(1)
2
>>> column[1]
2
"""
if index < -self.row_count or index >= self.row_count:
raise IndexOutOfBoundsError(index)
Expand Down Expand Up @@ -435,7 +437,7 @@ def count_if(
"""
Return how many values in the column satisfy the predicate.
The predicate can return one of three values:
The predicate can return one of three results:
* True, if the value satisfies the predicate.
* False, if the value does not satisfy the predicate.
Expand All @@ -459,11 +461,6 @@ def count_if(
count:
The number of values in the column that satisfy the predicate.
Raises
------
TypeError
If the predicate does not return a boolean cell.
Examples
--------
>>> from safeds.data.tabular.containers import Column
Expand Down
25 changes: 24 additions & 1 deletion src/safeds/data/tabular/containers/_row.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def schema(self) -> Schema:
@abstractmethod
def get_value(self, name: str) -> Cell:
"""
Get the value of the specified column.
Get the value of the specified column. This is equivalent to using the `[]` operator (indexed access).
Parameters
----------
Expand All @@ -84,6 +84,29 @@ def get_value(self, name: str) -> Cell:
------
ColumnNotFoundError
If the column name does not exist.
Examples
--------
>>> from safeds.data.tabular.containers import Table
>>> table = Table({"col1": [1, 2], "col2": [3, 4]})
>>> table.remove_rows(lambda row: row.get_value("col1") == 1)
+------+------+
| col1 | col2 |
| --- | --- |
| i64 | i64 |
+=============+
| 2 | 4 |
+------+------+
>>> table.remove_rows(lambda row: row["col1"] == 1)
+------+------+
| col1 | col2 |
| --- | --- |
| i64 | i64 |
+=============+
| 2 | 4 |
+------+------+
"""

@abstractmethod
Expand Down

0 comments on commit b94a55e

Please sign in to comment.