From 9954986b1a5a3bf11c70cf9a82538b48ff840e12 Mon Sep 17 00:00:00 2001 From: Lars Reimann Date: Tue, 11 Jul 2023 11:29:20 +0200 Subject: [PATCH] feat: rename several `Table` methods for consistency (#445) Closes #439 ### Summary of Changes * Rename `group_by` to `group_rows_by` * Rename `split` to `split_rows` * Rename `summary` to `summarize_statistics` --- docs/development/project_guidelines.md | 4 ++-- docs/tutorials/getting_started.ipynb | 2 +- src/safeds/data/tabular/containers/_table.py | 10 +++++----- .../_table/{test_group_by.py => test_group_rows_by.py} | 4 ++-- .../_table/{test_split.py => test_split_rows.py} | 6 +++--- .../{test_summary.py => test_summarize_statistics.py} | 6 +++--- 6 files changed, 16 insertions(+), 16 deletions(-) rename tests/safeds/data/tabular/containers/_table/{test_group_by.py => test_group_rows_by.py} (89%) rename tests/safeds/data/tabular/containers/_table/{test_split.py => test_split_rows.py} (92%) rename tests/safeds/data/tabular/containers/_table/{test_summary.py => test_summarize_statistics.py} (95%) diff --git a/docs/development/project_guidelines.md b/docs/development/project_guidelines.md index 22cfcbb87..673044408 100644 --- a/docs/development/project_guidelines.md +++ b/docs/development/project_guidelines.md @@ -265,13 +265,13 @@ Passing values that are commonly used together around separately is tedious, ver !!! success "**DO** (client code):" ```py - training_data, validation_data = split(full_data) + training_data, validation_data = split_rows(full_data) ``` !!! failure "**DON'T** (client code):" ```py - training_feature_vectors, validation_feature_vectors, training_target_values, validation_target_values = split(feature_vectors, target_values) + training_feature_vectors, validation_feature_vectors, training_target_values, validation_target_values = split_rows(feature_vectors, target_values) ``` ## Docstrings diff --git a/docs/tutorials/getting_started.ipynb b/docs/tutorials/getting_started.ipynb index 8ffd6b63c..87c90c698 100644 --- a/docs/tutorials/getting_started.ipynb +++ b/docs/tutorials/getting_started.ipynb @@ -52,7 +52,7 @@ "execution_count": 2, "outputs": [], "source": [ - "split_tuple = titanic.split(0.60)\n", + "split_tuple = titanic.split_rows(0.60)\n", "\n", "train_table = split_tuple[0]\n", "test_table = split_tuple[1]\n", diff --git a/src/safeds/data/tabular/containers/_table.py b/src/safeds/data/tabular/containers/_table.py index 176585411..c7ce1142c 100644 --- a/src/safeds/data/tabular/containers/_table.py +++ b/src/safeds/data/tabular/containers/_table.py @@ -695,7 +695,7 @@ def get_row(self, index: int) -> Row: # Information # ------------------------------------------------------------------------------------------------------------------ - def summary(self) -> Table: + def summarize_statistics(self) -> Table: """ Return a table with a number of statistical key values. @@ -710,7 +710,7 @@ def summary(self) -> Table: -------- >>> from safeds.data.tabular.containers import Table >>> table = Table.from_dict({"a": [1, 3], "b": [2, 4]}) - >>> table.summary() + >>> table.summarize_statistics() metrics a b 0 maximum 3 4 1 minimum 1 2 @@ -1048,7 +1048,7 @@ def filter_rows(self, query: Callable[[Row], bool]) -> Table: _T = TypeVar("_T") - def group_by(self, key_selector: Callable[[Row], _T]) -> dict[_T, Table]: + def group_rows_by(self, key_selector: Callable[[Row], _T]) -> dict[_T, Table]: """ Return a dictionary with the output tables as values and the keys from the key_selector. @@ -1595,7 +1595,7 @@ def sort_rows(self, comparator: Callable[[Row, Row], int]) -> Table: rows.sort(key=functools.cmp_to_key(comparator)) return Table.from_rows(rows) - def split(self, percentage_in_first: float) -> tuple[Table, Table]: + def split_rows(self, percentage_in_first: float) -> tuple[Table, Table]: """ Split the table into two new tables. @@ -1621,7 +1621,7 @@ def split(self, percentage_in_first: float) -> tuple[Table, Table]: -------- >>> from safeds.data.tabular.containers import Table >>> table = Table.from_dict({"temperature": [10, 15, 20, 25, 30], "sales": [54, 74, 90, 206, 210]}) - >>> slices = table.split(0.4) + >>> slices = table.split_rows(0.4) >>> slices[0] temperature sales 0 10 54 diff --git a/tests/safeds/data/tabular/containers/_table/test_group_by.py b/tests/safeds/data/tabular/containers/_table/test_group_rows_by.py similarity index 89% rename from tests/safeds/data/tabular/containers/_table/test_group_by.py rename to tests/safeds/data/tabular/containers/_table/test_group_rows_by.py index cfb38db36..2fb88a8f3 100644 --- a/tests/safeds/data/tabular/containers/_table/test_group_by.py +++ b/tests/safeds/data/tabular/containers/_table/test_group_rows_by.py @@ -30,6 +30,6 @@ ], ids=["select by row1", "different types in column", "empty table", "table with no rows"], ) -def test_group_by(table: Table, selector: Callable, expected: dict) -> None: - out = table.group_by(selector) +def test_should_group_rows(table: Table, selector: Callable, expected: dict) -> None: + out = table.group_rows_by(selector) assert out == expected diff --git a/tests/safeds/data/tabular/containers/_table/test_split.py b/tests/safeds/data/tabular/containers/_table/test_split_rows.py similarity index 92% rename from tests/safeds/data/tabular/containers/_table/test_split.py rename to tests/safeds/data/tabular/containers/_table/test_split_rows.py index 36789a346..917970452 100644 --- a/tests/safeds/data/tabular/containers/_table/test_split.py +++ b/tests/safeds/data/tabular/containers/_table/test_split_rows.py @@ -34,7 +34,7 @@ def test_should_split_table( result_train_table: Table, percentage_in_first: int, ) -> None: - train_table, test_table = table.split(percentage_in_first) + train_table, test_table = table.split_rows(percentage_in_first) assert result_test_table == test_table assert result_train_table.schema == train_table.schema assert result_train_table == train_table @@ -52,10 +52,10 @@ def test_should_raise_if_value_not_in_range(percentage_in_first: float) -> None: table = Table({"col1": [1, 2, 1], "col2": [1, 2, 4]}) with pytest.raises(ValueError, match=r"The given percentage is not between 0 and 1"): - table.split(percentage_in_first) + table.split_rows(percentage_in_first) def test_should_split_empty_table() -> None: - t1, t2 = Table().split(0.4) + t1, t2 = Table().split_rows(0.4) assert t1.number_of_rows == 0 assert t2.number_of_rows == 0 diff --git a/tests/safeds/data/tabular/containers/_table/test_summary.py b/tests/safeds/data/tabular/containers/_table/test_summarize_statistics.py similarity index 95% rename from tests/safeds/data/tabular/containers/_table/test_summary.py rename to tests/safeds/data/tabular/containers/_table/test_summarize_statistics.py index f4abaa988..54185e6ca 100644 --- a/tests/safeds/data/tabular/containers/_table/test_summary.py +++ b/tests/safeds/data/tabular/containers/_table/test_summarize_statistics.py @@ -135,6 +135,6 @@ ], ids=["Column of integers and Column of characters", "empty", "empty with columns", "Column of None"], ) -def test_should_make_summary(table: Table, expected: Table) -> None: - assert expected.schema == table.summary().schema - assert expected == table.summary() +def test_should_summarize_statistics(table: Table, expected: Table) -> None: + assert expected.schema == table.summarize_statistics().schema + assert expected == table.summarize_statistics()