Skip to content

Commit

Permalink
feat: move exceptions into subpackages (#177)
Browse files Browse the repository at this point in the history
### Summary of Changes

* Move exceptions related to ML to `safeds.ml.exceptions`.
* Move exceptions related to tabular data to
`safeds.data.tabular.exceptions`.
  • Loading branch information
lars-reimann authored Apr 6, 2023
1 parent 9449dbb commit 10b17fd
Show file tree
Hide file tree
Showing 46 changed files with 70 additions and 65 deletions.
4 changes: 2 additions & 2 deletions src/safeds/data/tabular/containers/_column.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@

from safeds.data.image.containers import Image
from safeds.data.image.typing import ImageFormat
from safeds.data.tabular.typing import ColumnType
from safeds.exceptions import (
from safeds.data.tabular.exceptions import (
ColumnLengthMismatchError,
ColumnSizeError,
IndexOutOfBoundsError,
NonNumericColumnError,
)
from safeds.data.tabular.typing import ColumnType

if TYPE_CHECKING:
from collections.abc import Callable, Iterable, Iterator
Expand Down
2 changes: 1 addition & 1 deletion src/safeds/data/tabular/containers/_row.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
from IPython.core.display_functions import DisplayHandle, display
from pandas.core.util.hashing import hash_pandas_object

from safeds.data.tabular.exceptions import UnknownColumnNameError
from safeds.data.tabular.typing import ColumnType, Schema
from safeds.exceptions import UnknownColumnNameError


class Row:
Expand Down
4 changes: 2 additions & 2 deletions src/safeds/data/tabular/containers/_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@

from safeds.data.image.containers import Image
from safeds.data.image.typing import ImageFormat
from safeds.data.tabular.typing import ColumnType, Schema
from safeds.exceptions import (
from safeds.data.tabular.exceptions import (
ColumnLengthMismatchError,
ColumnSizeError,
DuplicateColumnNameError,
Expand All @@ -26,6 +25,7 @@
SchemaMismatchError,
UnknownColumnNameError,
)
from safeds.data.tabular.typing import ColumnType, Schema

from ._column import Column
from ._row import Row
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Custom exceptions that can be raised by the `safe-ds` package."""
"""Custom exceptions that can be raised when working with tabular data."""

from ._data_exceptions import (
from ._exceptions import (
ColumnLengthMismatchError,
ColumnSizeError,
DuplicateColumnNameError,
Expand All @@ -12,27 +12,15 @@
TransformerNotFittedError,
UnknownColumnNameError,
)
from ._ml_exceptions import (
DatasetContainsTargetError,
DatasetMissesFeaturesError,
LearningError,
ModelNotFittedError,
PredictionError,
)

__all__ = [
"ColumnLengthMismatchError",
"ColumnSizeError",
"DatasetContainsTargetError",
"DatasetMissesFeaturesError",
"DuplicateColumnNameError",
"IndexOutOfBoundsError",
"LearningError",
"MissingDataError",
"MissingSchemaError",
"ModelNotFittedError",
"NonNumericColumnError",
"PredictionError",
"SchemaMismatchError",
"TransformerNotFittedError",
"UnknownColumnNameError",
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion src/safeds/data/tabular/transformation/_imputer.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
from sklearn.impute import SimpleImputer as sk_SimpleImputer

from safeds.data.tabular.containers import Table
from safeds.data.tabular.exceptions import TransformerNotFittedError, UnknownColumnNameError
from safeds.data.tabular.transformation._table_transformer import TableTransformer
from safeds.data.tabular.typing import ImputerStrategy
from safeds.exceptions import TransformerNotFittedError, UnknownColumnNameError


class Imputer(TableTransformer):
Expand Down
2 changes: 1 addition & 1 deletion src/safeds/data/tabular/transformation/_label_encoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
from sklearn.preprocessing import OrdinalEncoder as sk_OrdinalEncoder

from safeds.data.tabular.containers import Table
from safeds.data.tabular.exceptions import TransformerNotFittedError, UnknownColumnNameError
from safeds.data.tabular.transformation._table_transformer import (
InvertibleTableTransformer,
)
from safeds.exceptions import TransformerNotFittedError, UnknownColumnNameError


def warn(*_: Any, **__: Any) -> None:
Expand Down
2 changes: 1 addition & 1 deletion src/safeds/data/tabular/transformation/_one_hot_encoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
from sklearn.preprocessing import OneHotEncoder as sk_OneHotEncoder

from safeds.data.tabular.containers import Table
from safeds.data.tabular.exceptions import TransformerNotFittedError, UnknownColumnNameError
from safeds.data.tabular.transformation._table_transformer import (
InvertibleTableTransformer,
)
from safeds.exceptions import TransformerNotFittedError, UnknownColumnNameError


class OneHotEncoder(InvertibleTableTransformer):
Expand Down
2 changes: 1 addition & 1 deletion src/safeds/data/tabular/typing/_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
from dataclasses import dataclass
from typing import TYPE_CHECKING

from safeds.data.tabular.exceptions import UnknownColumnNameError
from safeds.data.tabular.typing._column_type import ColumnType
from safeds.exceptions import UnknownColumnNameError

if TYPE_CHECKING:
import pandas as pd
Expand Down
2 changes: 1 addition & 1 deletion src/safeds/ml/_util_sklearn.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from typing import Any

from safeds.data.tabular.containers import Table, TaggedTable
from safeds.exceptions import (
from safeds.ml.exceptions import (
DatasetContainsTargetError,
DatasetMissesFeaturesError,
LearningError,
Expand Down
17 changes: 17 additions & 0 deletions src/safeds/ml/exceptions/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
"""Custom exceptions that can be raised when working with ML models."""

from ._exceptions import (
DatasetContainsTargetError,
DatasetMissesFeaturesError,
LearningError,
ModelNotFittedError,
PredictionError,
)

__all__ = [
"DatasetContainsTargetError",
"DatasetMissesFeaturesError",
"LearningError",
"ModelNotFittedError",
"PredictionError",
]
File renamed without changes.
2 changes: 1 addition & 1 deletion src/safeds/ml/regression/_regressor.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from sklearn.metrics import mean_absolute_error as sk_mean_absolute_error
from sklearn.metrics import mean_squared_error as sk_mean_squared_error

from safeds.exceptions import ColumnLengthMismatchError
from safeds.data.tabular.exceptions import ColumnLengthMismatchError

if TYPE_CHECKING:
from safeds.data.tabular.containers import Column, Table, TaggedTable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import pandas as pd
import pytest
from safeds.data.tabular.containers import Table
from safeds.exceptions import NonNumericColumnError
from safeds.data.tabular.exceptions import NonNumericColumnError


def test_boxplot_complex() -> None:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pandas as pd
import pytest
from safeds.data.tabular.containers import Column
from safeds.exceptions import ColumnLengthMismatchError, NonNumericColumnError
from safeds.data.tabular.exceptions import ColumnLengthMismatchError, NonNumericColumnError


def test_correlation_with() -> None:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pandas as pd
import pytest
from safeds.data.tabular.containers import Column
from safeds.exceptions import IndexOutOfBoundsError
from safeds.data.tabular.exceptions import IndexOutOfBoundsError


def test_get_value_valid() -> None:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pandas as pd
import pytest
from safeds.data.tabular.containers import Column
from safeds.exceptions import IndexOutOfBoundsError
from safeds.data.tabular.exceptions import IndexOutOfBoundsError


def test_getitem_valid() -> None:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pandas as pd
import pytest
from safeds.data.tabular.containers import Column
from safeds.exceptions import ColumnSizeError
from safeds.data.tabular.exceptions import ColumnSizeError


@pytest.mark.parametrize(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pandas as pd
import pytest
from safeds.data.tabular.containers import Table
from safeds.exceptions import NonNumericColumnError
from safeds.data.tabular.exceptions import NonNumericColumnError


def test_maximum_invalid() -> None:
Expand Down
2 changes: 1 addition & 1 deletion tests/safeds/data/tabular/containers/_column/test_mean.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pandas as pd
import pytest
from safeds.data.tabular.containers import Table
from safeds.exceptions import NonNumericColumnError
from safeds.data.tabular.exceptions import NonNumericColumnError


def test_mean_invalid() -> None:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pandas as pd
import pytest
from safeds.data.tabular.containers import Table
from safeds.exceptions import NonNumericColumnError
from safeds.data.tabular.exceptions import NonNumericColumnError


def test_median_invalid() -> None:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pandas as pd
import pytest
from safeds.data.tabular.containers import Table
from safeds.exceptions import NonNumericColumnError
from safeds.data.tabular.exceptions import NonNumericColumnError


def test_minimum_invalid() -> None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import pandas as pd
import pytest
from safeds.data.tabular.containers import Column
from safeds.exceptions import ColumnSizeError
from safeds.data.tabular.exceptions import ColumnSizeError


@pytest.mark.parametrize(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import pandas as pd
import pytest
from safeds.data.tabular.containers import Column
from safeds.exceptions import ColumnSizeError
from safeds.data.tabular.exceptions import ColumnSizeError


@pytest.mark.parametrize(
Expand Down
2 changes: 1 addition & 1 deletion tests/safeds/data/tabular/containers/_column/test_sum.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pandas as pd
import pytest
from safeds.data.tabular.containers import Column
from safeds.exceptions import NonNumericColumnError
from safeds.data.tabular.exceptions import NonNumericColumnError


def test_sum_valid() -> None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
import pytest
from _pytest.python_api import raises
from safeds.data.tabular.containers import Column, Table
from safeds.data.tabular.exceptions import ColumnSizeError, DuplicateColumnNameError
from safeds.data.tabular.typing import ColumnType, Integer, String
from safeds.exceptions import ColumnSizeError, DuplicateColumnNameError


@pytest.mark.parametrize(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import pandas as pd
from _pytest.python_api import raises
from safeds.data.tabular.containers import Row, Table
from safeds.data.tabular.exceptions import SchemaMismatchError
from safeds.data.tabular.typing import Integer, Schema, String
from safeds.exceptions import SchemaMismatchError


def test_add_row_valid() -> None:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pandas as pd
import pytest
from safeds.data.tabular.containers import Column, Table
from safeds.exceptions import MissingDataError
from safeds.data.tabular.exceptions import MissingDataError

from tests.helpers import resolve_resource_path

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest
from safeds.data.tabular.containers import Row, Table
from safeds.exceptions import MissingDataError
from safeds.data.tabular.exceptions import MissingDataError

from tests.helpers import resolve_resource_path

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pandas as pd
import pytest
from safeds.data.tabular.containers import Column, Table
from safeds.exceptions import UnknownColumnNameError
from safeds.data.tabular.exceptions import UnknownColumnNameError


def test_get_column_valid() -> None:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest
from safeds.data.tabular.containers import Table
from safeds.exceptions import IndexOutOfBoundsError
from safeds.data.tabular.exceptions import IndexOutOfBoundsError

from tests.helpers import resolve_resource_path

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest
from safeds.data.tabular.containers import Table
from safeds.exceptions import UnknownColumnNameError
from safeds.data.tabular.exceptions import UnknownColumnNameError

from tests.helpers import resolve_resource_path

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import pandas as pd
import pytest
from safeds.data.tabular.containers import Table
from safeds.exceptions import UnknownColumnNameError
from safeds.data.tabular.exceptions import UnknownColumnNameError


def test_lineplot(monkeypatch: _pytest.monkeypatch) -> None:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest
from safeds.data.tabular.containers import Table
from safeds.exceptions import UnknownColumnNameError
from safeds.data.tabular.exceptions import UnknownColumnNameError

from tests.helpers import resolve_resource_path

Expand Down
2 changes: 1 addition & 1 deletion tests/safeds/data/tabular/containers/_table/test_rename.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest
from safeds.data.tabular.containers import Table
from safeds.exceptions import DuplicateColumnNameError, UnknownColumnNameError
from safeds.data.tabular.exceptions import DuplicateColumnNameError, UnknownColumnNameError

from tests.helpers import resolve_resource_path

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pandas as pd
import pytest
from safeds.data.tabular.containers import Column, Table
from safeds.exceptions import (
from safeds.data.tabular.exceptions import (
ColumnSizeError,
DuplicateColumnNameError,
UnknownColumnNameError,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import pandas as pd
import pytest
from safeds.data.tabular.containers import Table
from safeds.exceptions import UnknownColumnNameError
from safeds.data.tabular.exceptions import UnknownColumnNameError


def test_scatterplot(monkeypatch: _pytest.monkeypatch) -> None:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pandas as pd
import pytest
from safeds.data.tabular.containers import Column, Table
from safeds.exceptions import ColumnSizeError, DuplicateColumnNameError
from safeds.data.tabular.exceptions import ColumnSizeError, DuplicateColumnNameError

from tests.helpers import resolve_resource_path

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest
from safeds.data.tabular.containers import Table
from safeds.exceptions import UnknownColumnNameError
from safeds.data.tabular.exceptions import UnknownColumnNameError

from tests.helpers import resolve_resource_path

Expand Down
Loading

0 comments on commit 10b17fd

Please sign in to comment.