Skip to content

Commit

Permalink
test: improve coverage (#241)
Browse files Browse the repository at this point in the history
### Summary of Changes

* Remove unused or outdated code
* Improve test coverage for remaining code

---------

Co-authored-by: megalinter-bot <129584137+megalinter-bot@users.noreply.github.com>
  • Loading branch information
lars-reimann and megalinter-bot authored Apr 22, 2023
1 parent f2769f5 commit 4f08a2c
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 57 deletions.
3 changes: 0 additions & 3 deletions src/safeds/data/tabular/containers/_column.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,6 @@ def __eq__(self, other: object) -> bool:
def __getitem__(self, index: int) -> Any:
return self.get_value(index)

def __hash__(self) -> int:
return hash(self._data)

def __iter__(self) -> Iterator[Any]:
return iter(self._data)

Expand Down
3 changes: 1 addition & 2 deletions src/safeds/data/tabular/containers/_row.py
Original file line number Diff line number Diff line change
Expand Up @@ -467,5 +467,4 @@ def _repr_html_(self) -> str:
output : str
The generated HTML.
"""
# noinspection PyProtectedMember
return self._data._repr_html_()
return self._data.to_html(max_rows=1, max_cols=self._data.shape[1], notebook=True)
30 changes: 0 additions & 30 deletions src/safeds/data/tabular/containers/_tagged_table.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
from collections.abc import Iterable

from IPython.core.display_functions import DisplayHandle

from safeds.data.tabular.containers import Column, Table
from safeds.data.tabular.typing import Schema

Expand Down Expand Up @@ -50,16 +48,6 @@ def __init__(
self._features: Table = self.keep_only_columns(feature_names)
self._target: Column = self.get_column(target_name)

def __repr__(self) -> str:
tmp = self._features.add_column(self._target)
header_info = "Target Column is '" + self._target.name + "'\n"
return header_info + tmp.__repr__()

def __str__(self) -> str:
tmp = self._features.add_column(self._target)
header_info = "Target Column is '" + self._target.name + "'\n"
return header_info + tmp.__str__()

# ------------------------------------------------------------------------------------------------------------------
# Properties
# ------------------------------------------------------------------------------------------------------------------
Expand All @@ -71,21 +59,3 @@ def features(self) -> Table:
@property
def target(self) -> Column:
return self._target

# ------------------------------------------------------------------------------------------------------------------
# IPython integration
# ------------------------------------------------------------------------------------------------------------------

def _ipython_display_(self) -> DisplayHandle:
"""
Return a display object for the column to be used in Jupyter Notebooks.
Returns
-------
output : DisplayHandle
Output object.
"""
tmp = self._features.add_column(self._target)
header_info = "Target Column is '" + self._target.name + "'\n"
print(header_info) # noqa: T201
return tmp._ipython_display_()
2 changes: 0 additions & 2 deletions src/safeds/data/tabular/exceptions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
DuplicateColumnNameError,
IndexOutOfBoundsError,
MissingDataError,
MissingSchemaError,
NonNumericColumnError,
SchemaMismatchError,
TransformerNotFittedError,
Expand All @@ -19,7 +18,6 @@
"DuplicateColumnNameError",
"IndexOutOfBoundsError",
"MissingDataError",
"MissingSchemaError",
"NonNumericColumnError",
"SchemaMismatchError",
"TransformerNotFittedError",
Expand Down
7 changes: 0 additions & 7 deletions src/safeds/data/tabular/exceptions/_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,6 @@ def __init__(self) -> None:
super().__init__("Failed because at least two schemas didn't match.")


class MissingSchemaError(Exception):
"""Exception raised when a required schema is missing."""

def __init__(self) -> None:
super().__init__("Failed because a required schema is missing.")


class ColumnLengthMismatchError(Exception):
"""Exception raised when the lengths of two or more columns do not match."""

Expand Down
9 changes: 8 additions & 1 deletion src/safeds/data/tabular/typing/_imputer_strategy.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,11 @@ class ImputerStrategy(ABC):

@abstractmethod
def _augment_imputer(self, imputer: sk_SimpleImputer) -> None:
pass
"""
Set the imputer strategy of the given imputer.
Parameters
----------
imputer: SimpleImputer
The imputer to augment.
"""
18 changes: 6 additions & 12 deletions src/safeds/ml/exceptions/_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,12 @@ class LearningError(Exception):
Parameters
----------
reason: str | None
reason: str
The reason for the error.
"""

def __init__(self, reason: str | None):
if reason is None:
super().__init__("Error occurred while learning")
else:
super().__init__(f"Error occurred while learning: {reason}")
def __init__(self, reason: str):
super().__init__(f"Error occurred while learning: {reason}")


class ModelNotFittedError(Exception):
Expand All @@ -56,12 +53,9 @@ class PredictionError(Exception):
Parameters
----------
reason: str | None
reason: str
The reason for the error.
"""

def __init__(self, reason: str | None):
if reason is None:
super().__init__("Error occurred while predicting")
else:
super().__init__(f"Error occurred while predicting: {reason}")
def __init__(self, reason: str):
super().__init__(f"Error occurred while predicting: {reason}")
15 changes: 15 additions & 0 deletions tests/safeds/data/tabular/transformation/test_imputer.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,21 @@
from safeds.data.tabular.typing import ImputerStrategy


class TestStrategy:
class TestStr:
@pytest.mark.parametrize(
("strategy", "expected"),
[
(Imputer.Strategy.Constant(0), "Constant(0)"),
(Imputer.Strategy.Mean(), "Mean"),
(Imputer.Strategy.Median(), "Median"),
(Imputer.Strategy.Mode(), "Mode"),
],
)
def test_should_return_correct_string_representation(self, strategy: ImputerStrategy, expected: str) -> None:
assert str(strategy) == expected


class TestFit:
def test_should_raise_if_column_not_found(self) -> None:
table = Table.from_dict(
Expand Down

0 comments on commit 4f08a2c

Please sign in to comment.