diff --git a/benchmarks/table/row_operations.py b/benchmarks/table/row_operations.py index 84757c0d8..376d909f4 100644 --- a/benchmarks/table/row_operations.py +++ b/benchmarks/table/row_operations.py @@ -1,9 +1,9 @@ from timeit import timeit import polars as pl -from safeds.data.tabular.containers import Table from benchmarks.table.utils import create_synthetic_table +from safeds.data.tabular.containers import Table REPETITIONS = 10 @@ -21,7 +21,7 @@ def _run_remove_rows_with_outliers() -> None: def _run_remove_rows() -> None: - table.remove_rows(lambda row: row.get_value("column_0") % 2 == 0)._lazy_frame.collect() + table.remove_rows(lambda row: row["column_0"] % 2 == 0)._lazy_frame.collect() def _run_remove_rows_by_column() -> None: @@ -37,7 +37,7 @@ def _run_slice_rows() -> None: def _run_sort_rows() -> None: - table.sort_rows(lambda row: row.get_value("column_0"))._lazy_frame.collect() + table.sort_rows(lambda row: row["column_0"])._lazy_frame.collect() def _run_sort_rows_by_column() -> None: diff --git a/docs/development/guidelines/documentation.md b/docs/development/guidelines/documentation.md index 0067f6ea1..02e793e9a 100644 --- a/docs/development/guidelines/documentation.md +++ b/docs/development/guidelines/documentation.md @@ -111,7 +111,7 @@ Examples -------- >>> from safeds.data.tabular.containers import Row >>> row = Row({"a": 1, "b": 2}) ->>> row.get_value("a") +>>> row.get_cell("a") 1 """ ``` diff --git a/docs/tutorials/data_processing.ipynb b/docs/tutorials/data_processing.ipynb index e5803137f..ae9d61a6c 100644 --- a/docs/tutorials/data_processing.ipynb +++ b/docs/tutorials/data_processing.ipynb @@ -434,7 +434,7 @@ ], "source": [ "titanic.remove_rows(\n", - " lambda row: row.get_value(\"age\") < 1\n", + " lambda row: row[\"age\"] < 1\n", ")" ] }, diff --git a/src/safeds/data/tabular/containers/_lazy_vectorized_row.py b/src/safeds/data/tabular/containers/_lazy_vectorized_row.py index 5281bc126..b54b60ae6 100644 --- a/src/safeds/data/tabular/containers/_lazy_vectorized_row.py +++ b/src/safeds/data/tabular/containers/_lazy_vectorized_row.py @@ -64,7 +64,7 @@ def schema(self) -> Schema: # Column operations # ------------------------------------------------------------------------------------------------------------------ - def get_value(self, name: str) -> _LazyCell: + def get_cell(self, name: str) -> _LazyCell: import polars as pl _check_columns_exist(self._table, name) diff --git a/src/safeds/data/tabular/containers/_row.py b/src/safeds/data/tabular/containers/_row.py index b21aed44e..ec3a5d3a3 100644 --- a/src/safeds/data/tabular/containers/_row.py +++ b/src/safeds/data/tabular/containers/_row.py @@ -28,7 +28,7 @@ def __contains__(self, name: Any) -> bool: def __eq__(self, other: object) -> bool: ... def __getitem__(self, name: str) -> Cell: - return self.get_value(name) + return self.get_cell(name) @abstractmethod def __hash__(self) -> int: ... @@ -66,9 +66,9 @@ def schema(self) -> Schema: # ------------------------------------------------------------------------------------------------------------------ @abstractmethod - def get_value(self, name: str) -> Cell: + def get_cell(self, name: str) -> Cell: """ - Get the value of the specified column. This is equivalent to using the `[]` operator (indexed access). + Get the cell in the specified column. This is equivalent to using the `[]` operator (indexed access). Parameters ---------- @@ -77,8 +77,8 @@ def get_value(self, name: str) -> Cell: Returns ------- - value: - The value of the column. + cell: + The cell in the specified column. Raises ------ @@ -89,7 +89,7 @@ def get_value(self, name: str) -> Cell: -------- >>> 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) + >>> table.remove_rows(lambda row: row.get_cell("col1") == 1) +------+------+ | col1 | col2 | | --- | --- | diff --git a/src/safeds/data/tabular/containers/_table.py b/src/safeds/data/tabular/containers/_table.py index 4ef0cb8be..67432558c 100644 --- a/src/safeds/data/tabular/containers/_table.py +++ b/src/safeds/data/tabular/containers/_table.py @@ -527,7 +527,7 @@ def add_computed_column( -------- >>> from safeds.data.tabular.containers import Table >>> table = Table({"a": [1, 2, 3], "b": [4, 5, 6]}) - >>> table.add_computed_column("c", lambda row: row.get_value("a") + row.get_value("b")) + >>> table.add_computed_column("c", lambda row: row["a"] + row["b"]) +-----+-----+-----+ | a | b | c | | --- | --- | --- | @@ -1135,7 +1135,7 @@ def remove_rows( -------- >>> from safeds.data.tabular.containers import Table >>> table = Table({"a": [1, 2, 3], "b": [4, 5, 6]}) - >>> table.remove_rows(lambda row: row.get_value("a") == 2) + >>> table.remove_rows(lambda row: row["a"] == 2) +-----+-----+ | a | b | | --- | --- | @@ -1428,7 +1428,7 @@ def sort_rows( -------- >>> from safeds.data.tabular.containers import Table >>> table = Table({"a": [2, 1, 3], "b": [1, 1, 2]}) - >>> table.sort_rows(lambda row: row.get_value("a") - row.get_value("b")) + >>> table.sort_rows(lambda row: row["a"] - row["b"]) +-----+-----+ | a | b | | --- | --- | diff --git a/tests/safeds/data/tabular/containers/_row/test_get_value.py b/tests/safeds/data/tabular/containers/_row/test_get_cell.py similarity index 83% rename from tests/safeds/data/tabular/containers/_row/test_get_value.py rename to tests/safeds/data/tabular/containers/_row/test_get_cell.py index dac4f8ee7..4bd0214f1 100644 --- a/tests/safeds/data/tabular/containers/_row/test_get_value.py +++ b/tests/safeds/data/tabular/containers/_row/test_get_cell.py @@ -1,10 +1,10 @@ import re import pytest -from safeds.data.tabular.containers import Row, Table + +from safeds.data.tabular.containers import Table from safeds.data.tabular.containers._lazy_vectorized_row import _LazyVectorizedRow from safeds.exceptions import ColumnNotFoundError - from tests.helpers import assert_row_operation_works @@ -22,7 +22,7 @@ def test_should_get_correct_item(table_data: dict, column_name: str, target: int, expected: dict) -> None: assert_row_operation_works( table_data, - lambda table: table.remove_rows(lambda row: row.get_value(column_name).eq(target)), + lambda table: table.remove_rows(lambda row: row.get_cell(column_name).eq(target)), expected, ) @@ -41,6 +41,6 @@ def test_should_get_correct_item(table_data: dict, column_name: str, target: int ], ) def test_should_raise_column_not_found_error(table: Table, column_name: str) -> None: - row: Row[any] = _LazyVectorizedRow(table=table) + row = _LazyVectorizedRow(table=table) with pytest.raises(ColumnNotFoundError, match=re.escape(f"Could not find column(s):\n - '{column_name}'")): - row.get_value(column_name) + row.get_cell(column_name) diff --git a/tests/safeds/data/tabular/containers/_table/test_remove_rows.py b/tests/safeds/data/tabular/containers/_table/test_remove_rows.py index 5ca8829a4..928663cb2 100644 --- a/tests/safeds/data/tabular/containers/_table/test_remove_rows.py +++ b/tests/safeds/data/tabular/containers/_table/test_remove_rows.py @@ -1,6 +1,7 @@ from typing import Any import pytest + from safeds.data.tabular.containers import Table @@ -26,6 +27,6 @@ ], ) def test_should_remove_rows(table1: Table, filter_column: str, filter_value: Any, table2: Table) -> None: - table1 = table1.remove_rows(lambda row: row.get_value(filter_column) == filter_value) + table1 = table1.remove_rows(lambda row: row[filter_column] == filter_value) assert table1.schema == table2.schema assert table2 == table1