Skip to content

Commit

Permalink
feat: deprecate Table.add_column and Table.add_row (#723)
Browse files Browse the repository at this point in the history
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`.
  • Loading branch information
lars-reimann committed May 5, 2024
1 parent 923a6c2 commit 5dd9d02
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 10 deletions.
7 changes: 7 additions & 0 deletions .github/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
3 changes: 2 additions & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 19 additions & 9 deletions src/safeds/data/tabular/containers/_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
"""
Expand Down Expand Up @@ -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:
Expand All @@ -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

Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit 5dd9d02

Please sign in to comment.