From 5dd9d026e404e02bfe0905e8328d5b621f36c219 Mon Sep 17 00:00:00 2001 From: Lars Reimann Date: Sun, 5 May 2024 16:20:06 +0200 Subject: [PATCH] feat: deprecate `Table.add_column` and `Table.add_row` (#723) Closes #722 ### Summary of Changes * Deprecate `Table.add_column` in favor of `Table.add_columns`. * Deprecate `Table.add_row` in favor of `Table.add_rows`. --- .github/README.md | 7 +++++ docs/README.md | 3 ++- src/safeds/data/tabular/containers/_table.py | 28 +++++++++++++------- 3 files changed, 28 insertions(+), 10 deletions(-) diff --git a/.github/README.md b/.github/README.md index 982563742..5d6aca169 100644 --- a/.github/README.md +++ b/.github/README.md @@ -31,6 +31,13 @@ Get the latest version from [PyPI](https://pypi.org/project/safe-ds): pip install safe-ds ``` +On a Windows PC with an NVIDIA graphics card, you may also want to install the CUDA versions of `torch` and +`torchvision`: + +```shell +pip install --upgrade torch torchvision --index-url https://download.pytorch.org/whl/cu121 +``` + ## Documentation You can find the full documentation [here](https://library.safeds.com). diff --git a/docs/README.md b/docs/README.md index 03cadd25b..bb7a4f31c 100644 --- a/docs/README.md +++ b/docs/README.md @@ -31,7 +31,8 @@ Get the latest version from [PyPI](https://pypi.org/project/safe-ds): pip install safe-ds ``` -On a Windows PC with an NVIDIA graphics card, you may also want to install the CUDA versions of `torch` and `torchvision`: +On a Windows PC with an NVIDIA graphics card, you may also want to install the CUDA versions of `torch` and +`torchvision`: ```shell pip install --upgrade torch torchvision --index-url https://download.pytorch.org/whl/cu121 diff --git a/src/safeds/data/tabular/containers/_table.py b/src/safeds/data/tabular/containers/_table.py index aa1ccfd80..2dbd9e18b 100644 --- a/src/safeds/data/tabular/containers/_table.py +++ b/src/safeds/data/tabular/containers/_table.py @@ -898,6 +898,9 @@ def add_column(self, column: Column) -> Table: The original table is not modified. + !!! warning "Deprecated" + Use [add_columns][safeds.data.tabular.containers._table.Table.add_columns] instead. + Returns ------- result: @@ -920,16 +923,13 @@ def add_column(self, column: Column) -> Table: 0 1 2 d 1 3 4 e """ - if self.has_column(column.name): - raise DuplicateColumnNameError(column.name) - - if column.number_of_rows != self.number_of_rows and self.number_of_columns != 0: - raise ColumnSizeError(str(self.number_of_rows), str(column._data.size)) + warnings.warn( + "This method is deprecated and will be removed in a future version. Use `Table.add_columns` instead.", + DeprecationWarning, + stacklevel=2, + ) - result = self._data.reset_index(drop=True) - result.columns = self._schema.column_names - result[column.name] = column._data - return Table._from_pandas_dataframe(result) + return self.add_columns([column]) def add_columns(self, columns: list[Column] | Table) -> Table: """ @@ -990,6 +990,9 @@ def add_row(self, row: Row) -> Table: The original table is not modified. + !!! warning "Deprecated" + Use [add_rows][safeds.data.tabular.containers._table.Table.add_rows] instead. + Parameters ---------- row: @@ -1015,6 +1018,12 @@ def add_row(self, row: Row) -> Table: 0 1 2 1 3 4 """ + warnings.warn( + "This method is deprecated and will be removed in a future version. Use `Table.add_rows` instead.", + DeprecationWarning, + stacklevel=2, + ) + import numpy as np import pandas as pd @@ -1161,6 +1170,7 @@ def filter_rows(self, query: Callable[[Row], bool]) -> Table: DeprecationWarning, stacklevel=2, ) + return self.keep_only_rows(query) _T = TypeVar("_T")