From 1651cc26dce42fe9d48603a3674e02401941e58d Mon Sep 17 00:00:00 2001 From: Lars Reimann Date: Fri, 24 Mar 2023 22:32:04 +0100 Subject: [PATCH 1/2] feat: rename a `Column` --- src/safeds/data/tabular/containers/_column.py | 16 ++++++++++++++++ .../tabular/containers/_column/test_rename.py | 13 +++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 tests/safeds/data/tabular/containers/_column/test_rename.py diff --git a/src/safeds/data/tabular/containers/_column.py b/src/safeds/data/tabular/containers/_column.py index f4c30bf59..1eb3b9d69 100644 --- a/src/safeds/data/tabular/containers/_column.py +++ b/src/safeds/data/tabular/containers/_column.py @@ -121,6 +121,22 @@ def _count_missing_values(self) -> int: """ return self._data.isna().sum() + def rename(self, new_name: str) -> Column: + """ + Return a new column with a new name. + + Parameters + ---------- + new_name : str + The new name of the column. + + Returns + ------- + column : Column + A new column with the new name. + """ + return Column(self._data, new_name) + def all(self, predicate: Callable[[Any], bool]) -> bool: """ Check if all values have a given property. diff --git a/tests/safeds/data/tabular/containers/_column/test_rename.py b/tests/safeds/data/tabular/containers/_column/test_rename.py new file mode 100644 index 000000000..26ea2e2fc --- /dev/null +++ b/tests/safeds/data/tabular/containers/_column/test_rename.py @@ -0,0 +1,13 @@ +from safeds.data.tabular.containers import Column + + +def test_should_return_new_column_with_new_name(): + column = Column([1, 2, 3], "A") + new_column = column.rename("B") + assert new_column.name == "B" + + +def test_should_not_change_name_of_original_column(): + column = Column([1, 2, 3], "A") + column.rename("B") + assert column.name == "A" From 0c7a8111bea66c690772471158829fa4945f85e0 Mon Sep 17 00:00:00 2001 From: Lars Reimann Date: Fri, 24 Mar 2023 22:35:18 +0100 Subject: [PATCH 2/2] feat: rename a `Column` --- tests/safeds/data/tabular/containers/_column/test_rename.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/safeds/data/tabular/containers/_column/test_rename.py b/tests/safeds/data/tabular/containers/_column/test_rename.py index 26ea2e2fc..e6a3d44ed 100644 --- a/tests/safeds/data/tabular/containers/_column/test_rename.py +++ b/tests/safeds/data/tabular/containers/_column/test_rename.py @@ -1,13 +1,13 @@ from safeds.data.tabular.containers import Column -def test_should_return_new_column_with_new_name(): +def test_should_return_new_column_with_new_name() -> None: column = Column([1, 2, 3], "A") new_column = column.rename("B") assert new_column.name == "B" -def test_should_not_change_name_of_original_column(): +def test_should_not_change_name_of_original_column() -> None: column = Column([1, 2, 3], "A") column.rename("B") assert column.name == "A"