Skip to content

Commit

Permalink
feat: compatibility with safe-ds v0.12.0 (#63)
Browse files Browse the repository at this point in the history
### Summary of Changes

Integrate API changes of [`safe-ds`
v0.12.0](https://github.com/Safe-DS/Stdlib/releases/tag/v0.12.0).

---------

Co-authored-by: megalinter-bot <129584137+megalinter-bot@users.noreply.github.com>
  • Loading branch information
lars-reimann and megalinter-bot committed May 11, 2023
1 parent 1795805 commit 356e3a4
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 114 deletions.
137 changes: 33 additions & 104 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ packages = [

[tool.poetry.dependencies]
python = "^3.10"
safe-ds = ">=0.11,<0.12"
safe-ds = ">=0.12,<0.13"

[tool.poetry.group.dev.dependencies]
pytest = "^7.2.1"
Expand Down
14 changes: 8 additions & 6 deletions src/safeds_examples/tabular/containers/_example_table.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from safeds.data.tabular.containers import Table
from safeds.data.tabular.exceptions import UnknownColumnNameError
from safeds.exceptions import UnknownColumnNameError


class ExampleTable(Table):
Expand All @@ -19,13 +19,15 @@ class ExampleTable(Table):
If a column name in `descriptions` does not exist in `table`.
"""

# noinspection PyMissingConstructor
def __init__(self, table: Table, column_descriptions: dict[str, str]) -> None:
# Check that all column names in `descriptions` exist in `table`
invalid_column_names = set(column_descriptions.keys()) - set(table.column_names)
if invalid_column_names:
raise UnknownColumnNameError(list(invalid_column_names))

super().__init__(table._data, table.schema)
self._data = table._data
self._schema = table.schema
self._descriptions = column_descriptions

@property
Expand All @@ -36,10 +38,10 @@ def column_descriptions(self) -> Table:
The name is stored in a column called `"Name"` and the description in a column called `"Description"`.
"""
return Table(
[
{"Name": column_name, "Description": self.get_column_description(column_name)}
for column_name in self.column_names
],
{
"Name": self.column_names,
"Description": [self.get_column_description(column_name) for column_name in self.column_names],
},
)

def get_column_description(self, column_name: str) -> str:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def test_returns_table(self) -> None:
assert isinstance(house_sales, Table)

def test_row_count(self, house_sales: Table) -> None:
assert house_sales.n_rows == 21613
assert house_sales.number_of_rows == 21613

def test_schema(self, house_sales: Table) -> None:
assert house_sales.schema == Schema(
Expand Down
2 changes: 1 addition & 1 deletion tests/safeds_examples/tabular/_titanic/test_titanic.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def test_returns_table(self) -> None:
assert isinstance(titanic, Table)

def test_row_count(self, titanic: Table) -> None:
assert titanic.n_rows == 1309
assert titanic.number_of_rows == 1309

def test_schema(self, titanic: Table) -> None:
assert titanic.schema == Schema(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest
from safeds.data.tabular.containers import Column, Table
from safeds.data.tabular.exceptions import UnknownColumnNameError
from safeds.exceptions import UnknownColumnNameError
from safeds_examples.tabular.containers import ExampleTable


Expand Down

0 comments on commit 356e3a4

Please sign in to comment.