Skip to content

Commit

Permalink
feat: rename Row.get_value to Row.get_cell (#947)
Browse files Browse the repository at this point in the history
### Summary of Changes

Rename `Row.get_value` to `Row.get_cell` to avoid confusion with
`Column.get_value`. The row method returns a cell, while the column
method returns an actual Python constant. The new name emphasizes this
difference.

---------

Co-authored-by: megalinter-bot <129584137+megalinter-bot@users.noreply.github.com>
  • Loading branch information
lars-reimann and megalinter-bot authored Nov 20, 2024
1 parent a3607d7 commit e77cb6c
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 21 deletions.
6 changes: 3 additions & 3 deletions benchmarks/table/row_operations.py
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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:
Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion docs/development/guidelines/documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
"""
```
Expand Down
2 changes: 1 addition & 1 deletion docs/tutorials/data_processing.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@
],
"source": [
"titanic.remove_rows(\n",
" lambda row: row.get_value(\"age\") < 1\n",
" lambda row: row[\"age\"] < 1\n",
")"
]
},
Expand Down
2 changes: 1 addition & 1 deletion src/safeds/data/tabular/containers/_lazy_vectorized_row.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 6 additions & 6 deletions src/safeds/data/tabular/containers/_row.py
Original file line number Diff line number Diff line change
Expand Up @@ -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: ...
Expand Down Expand Up @@ -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
----------
Expand All @@ -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
------
Expand All @@ -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 |
| --- | --- |
Expand Down
6 changes: 3 additions & 3 deletions src/safeds/data/tabular/containers/_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
| --- | --- | --- |
Expand Down Expand Up @@ -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 |
| --- | --- |
Expand Down Expand Up @@ -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 |
| --- | --- |
Expand Down
Original file line number Diff line number Diff line change
@@ -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


Expand All @@ -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,
)

Expand All @@ -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)
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from typing import Any

import pytest

from safeds.data.tabular.containers import Table


Expand All @@ -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

0 comments on commit e77cb6c

Please sign in to comment.