Skip to content

Commit

Permalink
fix: mark various API elements as internal (#587)
Browse files Browse the repository at this point in the history
Closes #582
Closes #585

### Summary of Changes

Mark the following API elements as internal:

* Static method `Schema.merge_multiple_schemas`
* Instance method `SupportVectorMachineKernel.get_sklearn_kernel`
* Module `config`

---------

Co-authored-by: megalinter-bot <[email protected]>
  • Loading branch information
lars-reimann and megalinter-bot authored Mar 30, 2024
1 parent ce53153 commit ea176fc
Show file tree
Hide file tree
Showing 12 changed files with 32 additions and 28 deletions.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions src/safeds/data/image/containers/_image.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import annotations

import sys
import io
import sys
import warnings
from pathlib import Path
from typing import TYPE_CHECKING
Expand All @@ -12,7 +12,7 @@
from PIL.Image import open as pil_image_open
from torch import Tensor

from safeds.config import _get_device
from safeds._config import _get_device

if TYPE_CHECKING:
from torch.types import Device
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 @@ -337,7 +337,7 @@ def from_rows(rows: list[Row]) -> Table:
dataframe: DataFrame = pd.concat(row_array, ignore_index=True)
dataframe.columns = column_names_compare

schema = Schema.merge_multiple_schemas([row.schema for row in rows])
schema = Schema._merge_multiple_schemas([row.schema for row in rows])

return Table._from_pandas_dataframe(dataframe, schema)

Expand Down Expand Up @@ -1012,7 +1012,7 @@ def add_row(self, row: Row) -> Table:

new_df = pd.concat([self._data, row._data]).infer_objects()
new_df.columns = self.column_names
schema = Schema.merge_multiple_schemas([self.schema, row.schema])
schema = Schema._merge_multiple_schemas([self.schema, row.schema])
result = Table._from_pandas_dataframe(new_df, schema)

for column in int_columns:
Expand Down
8 changes: 6 additions & 2 deletions src/safeds/data/tabular/typing/_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,11 @@ def __sizeof__(self) -> int:
-------
Size of this object in bytes.
"""
return sum(map(sys.getsizeof, self._schema.keys())) + sum(map(sys.getsizeof, self._schema.values())) + sys.getsizeof(self._schema)
return (
sum(map(sys.getsizeof, self._schema.keys()))
+ sum(map(sys.getsizeof, self._schema.values()))
+ sys.getsizeof(self._schema)
)

def __str__(self) -> str:
"""
Expand Down Expand Up @@ -237,7 +241,7 @@ def to_dict(self) -> dict[str, ColumnType]:
return dict(self._schema) # defensive copy

@staticmethod
def merge_multiple_schemas(schemas: list[Schema]) -> Schema:
def _merge_multiple_schemas(schemas: list[Schema]) -> Schema:
"""
Merge multiple schemas into one.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class SupportVectorMachineKernel(ABC):
"""The abstract base class of the different subclasses supported by the `Kernel`."""

@abstractmethod
def get_sklearn_kernel(self) -> object:
def _get_sklearn_kernel(self) -> object:
"""
Get the kernel of the given SupportVectorMachine.
Expand Down Expand Up @@ -85,7 +85,7 @@ def kernel(self) -> SupportVectorMachineKernel | None:

class Kernel:
class Linear(SupportVectorMachineKernel):
def get_sklearn_kernel(self) -> str:
def _get_sklearn_kernel(self) -> str:
"""
Get the name of the linear kernel.
Expand All @@ -102,7 +102,7 @@ def __init__(self, degree: int):
raise OutOfBoundsError(degree, name="degree", lower_bound=ClosedBound(1))
self._degree = degree

def get_sklearn_kernel(self) -> str:
def _get_sklearn_kernel(self) -> str:
"""
Get the name of the polynomial kernel.
Expand All @@ -114,7 +114,7 @@ def get_sklearn_kernel(self) -> str:
return "poly"

class Sigmoid(SupportVectorMachineKernel):
def get_sklearn_kernel(self) -> str:
def _get_sklearn_kernel(self) -> str:
"""
Get the name of the sigmoid kernel.
Expand All @@ -126,7 +126,7 @@ def get_sklearn_kernel(self) -> str:
return "sigmoid"

class RadialBasisFunction(SupportVectorMachineKernel):
def get_sklearn_kernel(self) -> str:
def _get_sklearn_kernel(self) -> str:
"""
Get the name of the radial basis function (RBF) kernel.
Expand Down
10 changes: 5 additions & 5 deletions src/safeds/ml/classical/regression/_support_vector_machine.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class SupportVectorMachineKernel(ABC):
"""The abstract base class of the different subclasses supported by the `Kernel`."""

@abstractmethod
def get_sklearn_kernel(self) -> object:
def _get_sklearn_kernel(self) -> object:
"""
Get the kernel of the given SupportVectorMachine.
Expand Down Expand Up @@ -85,7 +85,7 @@ def kernel(self) -> SupportVectorMachineKernel | None:

class Kernel:
class Linear(SupportVectorMachineKernel):
def get_sklearn_kernel(self) -> str:
def _get_sklearn_kernel(self) -> str:
"""
Get the name of the linear kernel.
Expand All @@ -102,7 +102,7 @@ def __init__(self, degree: int):
raise OutOfBoundsError(degree, name="degree", lower_bound=ClosedBound(1))
self._degree = degree

def get_sklearn_kernel(self) -> str:
def _get_sklearn_kernel(self) -> str:
"""
Get the name of the polynomial kernel.
Expand All @@ -114,7 +114,7 @@ def get_sklearn_kernel(self) -> str:
return "poly"

class Sigmoid(SupportVectorMachineKernel):
def get_sklearn_kernel(self) -> str:
def _get_sklearn_kernel(self) -> str:
"""
Get the name of the sigmoid kernel.
Expand All @@ -126,7 +126,7 @@ def get_sklearn_kernel(self) -> str:
return "sigmoid"

class RadialBasisFunction(SupportVectorMachineKernel):
def get_sklearn_kernel(self) -> str:
def _get_sklearn_kernel(self) -> str:
"""
Get the name of the radial basis function (RBF) kernel.
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import torch
from safeds.config import _get_device
from safeds._config import _get_device


def test_device() -> None:
Expand Down
6 changes: 3 additions & 3 deletions tests/safeds/data/tabular/typing/test_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ class TestMergeMultipleSchemas:
)
def test_should_raise_if_column_names_are_different(self, schemas: list[Schema], error_msg_regex: str) -> None:
with pytest.raises(UnknownColumnNameError, match=error_msg_regex):
Schema.merge_multiple_schemas(schemas)
Schema._merge_multiple_schemas(schemas)

@pytest.mark.parametrize(
("schemas", "expected"),
Expand Down Expand Up @@ -470,10 +470,10 @@ def test_should_raise_if_column_names_are_different(self, schemas: list[Schema],
],
)
def test_should_return_merged_schema(self, schemas: list[Schema], expected: Schema) -> None:
assert Schema.merge_multiple_schemas(schemas) == expected
assert Schema._merge_multiple_schemas(schemas) == expected
schemas.reverse()
assert (
Schema.merge_multiple_schemas(schemas) == expected
Schema._merge_multiple_schemas(schemas) == expected
) # test the reversed list because the first parameter is handled differently


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def test_should_be_passed_to_sklearn(self, training_set: TaggedTable) -> None:
def test_should_get_sklearn_kernel_linear(self) -> None:
svm = SupportVectorMachine(c=2, kernel=SupportVectorMachine.Kernel.Linear())
assert isinstance(svm.kernel, SupportVectorMachine.Kernel.Linear)
linear_kernel = svm.kernel.get_sklearn_kernel()
linear_kernel = svm.kernel._get_sklearn_kernel()
assert linear_kernel == "linear"

@pytest.mark.parametrize("degree", [-1, 0], ids=["minus_one", "zero"])
Expand All @@ -52,19 +52,19 @@ def test_should_raise_if_degree_less_than_1(self, degree: int) -> None:
def test_should_get_sklearn_kernel_polynomial(self) -> None:
svm = SupportVectorMachine(c=2, kernel=SupportVectorMachine.Kernel.Polynomial(degree=2))
assert isinstance(svm.kernel, SupportVectorMachine.Kernel.Polynomial)
poly_kernel = svm.kernel.get_sklearn_kernel()
poly_kernel = svm.kernel._get_sklearn_kernel()
assert poly_kernel == "poly"

def test_should_get_sklearn_kernel_sigmoid(self) -> None:
svm = SupportVectorMachine(c=2, kernel=SupportVectorMachine.Kernel.Sigmoid())
assert isinstance(svm.kernel, SupportVectorMachine.Kernel.Sigmoid)
sigmoid_kernel = svm.kernel.get_sklearn_kernel()
sigmoid_kernel = svm.kernel._get_sklearn_kernel()
assert sigmoid_kernel == "sigmoid"

def test_should_get_sklearn_kernel_rbf(self) -> None:
svm = SupportVectorMachine(c=2, kernel=SupportVectorMachine.Kernel.RadialBasisFunction())
assert isinstance(svm.kernel, SupportVectorMachine.Kernel.RadialBasisFunction)
rbf_kernel = svm.kernel.get_sklearn_kernel()
rbf_kernel = svm.kernel._get_sklearn_kernel()
assert rbf_kernel == "rbf"

def test_should_get_kernel_name(self) -> None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def test_should_be_passed_to_sklearn(self, training_set: TaggedTable) -> None:
def test_should_get_sklearn_kernel_linear(self) -> None:
svm = SupportVectorMachine(c=2, kernel=SupportVectorMachine.Kernel.Linear())
assert isinstance(svm.kernel, SupportVectorMachine.Kernel.Linear)
linear_kernel = svm.kernel.get_sklearn_kernel()
linear_kernel = svm.kernel._get_sklearn_kernel()
assert linear_kernel == "linear"

@pytest.mark.parametrize("degree", [-1, 0], ids=["minus_one", "zero"])
Expand All @@ -52,19 +52,19 @@ def test_should_raise_if_degree_less_than_1(self, degree: int) -> None:
def test_should_get_sklearn_kernel_polynomial(self) -> None:
svm = SupportVectorMachine(c=2, kernel=SupportVectorMachine.Kernel.Polynomial(degree=2))
assert isinstance(svm.kernel, SupportVectorMachine.Kernel.Polynomial)
poly_kernel = svm.kernel.get_sklearn_kernel()
poly_kernel = svm.kernel._get_sklearn_kernel()
assert poly_kernel == "poly"

def test_should_get_sklearn_kernel_sigmoid(self) -> None:
svm = SupportVectorMachine(c=2, kernel=SupportVectorMachine.Kernel.Sigmoid())
assert isinstance(svm.kernel, SupportVectorMachine.Kernel.Sigmoid)
sigmoid_kernel = svm.kernel.get_sklearn_kernel()
sigmoid_kernel = svm.kernel._get_sklearn_kernel()
assert sigmoid_kernel == "sigmoid"

def test_should_get_sklearn_kernel_rbf(self) -> None:
svm = SupportVectorMachine(c=2, kernel=SupportVectorMachine.Kernel.RadialBasisFunction())
assert isinstance(svm.kernel, SupportVectorMachine.Kernel.RadialBasisFunction)
rbf_kernel = svm.kernel.get_sklearn_kernel()
rbf_kernel = svm.kernel._get_sklearn_kernel()
assert rbf_kernel == "rbf"

def test_should_get_kernel_name(self) -> None:
Expand Down

0 comments on commit ea176fc

Please sign in to comment.