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..e6a3d44ed --- /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() -> 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() -> None: + column = Column([1, 2, 3], "A") + column.rename("B") + assert column.name == "A"