From 1b37cd64fe84969c6959249c4fca1f58394d703c Mon Sep 17 00:00:00 2001 From: grefrathc Date: Fri, 21 Jun 2024 15:44:29 +0200 Subject: [PATCH 01/39] issue #750 regularization strength for logistic classifier --- .../classification/_logistic_classifier.py | 11 ++++---- .../test_logistic_classifier.py | 26 +++++++++++++++++++ 2 files changed, 32 insertions(+), 5 deletions(-) create mode 100644 tests/safeds/ml/classical/classification/test_logistic_classifier.py diff --git a/src/safeds/ml/classical/classification/_logistic_classifier.py b/src/safeds/ml/classical/classification/_logistic_classifier.py index e312e6b25..0c8e2856b 100644 --- a/src/safeds/ml/classical/classification/_logistic_classifier.py +++ b/src/safeds/ml/classical/classification/_logistic_classifier.py @@ -17,9 +17,9 @@ class LogisticClassifier(Classifier): # Dunder methods # ------------------------------------------------------------------------------------------------------------------ - def __init__(self) -> None: + def __init__(self, c: float=1.0) -> None: super().__init__() - + self.c = c def __hash__(self) -> int: return _structural_hash( super().__hash__(), @@ -30,12 +30,13 @@ def __hash__(self) -> int: # ------------------------------------------------------------------------------------------------------------------ def _clone(self) -> LogisticClassifier: - return LogisticClassifier() - + return LogisticClassifier(c=self.c) + def _get_sklearn_model(self) -> ClassifierMixin: from sklearn.linear_model import LogisticRegression as SklearnLogisticRegression return SklearnLogisticRegression( random_state=_get_random_seed(), n_jobs=-1, - ) + C=self.c, + ) \ No newline at end of file diff --git a/tests/safeds/ml/classical/classification/test_logistic_classifier.py b/tests/safeds/ml/classical/classification/test_logistic_classifier.py new file mode 100644 index 000000000..768beae22 --- /dev/null +++ b/tests/safeds/ml/classical/classification/test_logistic_classifier.py @@ -0,0 +1,26 @@ +import pytest +from safeds.data.labeled.containers import TabularDataset +from safeds.data.tabular.containers import Table +from safeds.ml.classical.classification import LogisticClassifier + + +@pytest.fixture() +def training_set() -> TabularDataset: + table = Table({"col1": [1, 2, 3, 4], "col2": [1, 2, 3, 4]}) + return table.to_tabular_dataset(target_name="col1") + +class TestC: + def test_should_be_passed_to_fitted_model(self, training_set: TabularDataset) -> None: + fitted_model = LogisticClassifier(c=2).fit(training_set) + assert fitted_model.c == 2 + + def test_should_be_passed_to_sklearn(self, training_set: TabularDataset) -> None: + fitted_model = LogisticClassifier(c=2).fit(training_set) + assert fitted_model._wrapped_model is not None + assert fitted_model._wrapped_model.C == 2 + + def test_clone(self, training_set: TabularDataset) -> None: + fitted_model = LogisticClassifier(c=2).fit(training_set) + cloned_classifier = fitted_model._clone() + assert isinstance(cloned_classifier, LogisticClassifier) + assert cloned_classifier.c == fitted_model.c \ No newline at end of file From 4081bcadea317daa1cb2c7f1edd28c89f3ced4af Mon Sep 17 00:00:00 2001 From: grefrathc Date: Fri, 28 Jun 2024 10:40:02 +0200 Subject: [PATCH 02/39] first try --- src/safeds/data/tabular/containers/_table.py | 7 ++ .../tabular/containers/_table/test_join.py | 69 +++++++++++++++++++ 2 files changed, 76 insertions(+) create mode 100644 tests/safeds/data/tabular/containers/_table/test_join.py diff --git a/src/safeds/data/tabular/containers/_table.py b/src/safeds/data/tabular/containers/_table.py index 6f6282673..f728fb3b5 100644 --- a/src/safeds/data/tabular/containers/_table.py +++ b/src/safeds/data/tabular/containers/_table.py @@ -1702,6 +1702,13 @@ def inverse_transform_table(self, fitted_transformer: InvertibleTableTransformer """ return fitted_transformer.inverse_transform(self) + def join(self, rightTable : Table, + left_names: str | list[str], + rightNames: str | list[str], + *, mode: Literal["inner", "left", "outer"] = "inner", + ) -> Table: + self._data_frame().join(rightTable ) + def transform_table(self, fitted_transformer: TableTransformer) -> Table: """ Return a new table transformed by a **fitted** transformer. diff --git a/tests/safeds/data/tabular/containers/_table/test_join.py b/tests/safeds/data/tabular/containers/_table/test_join.py new file mode 100644 index 000000000..fcafce89b --- /dev/null +++ b/tests/safeds/data/tabular/containers/_table/test_join.py @@ -0,0 +1,69 @@ +import pytest +from safeds.data.tabular.containers import Table +from safeds.exceptions import ColumnNotFoundError + + +@pytest.mark.parametrize( + ("table_left, table_right, left_names, right_names, mode_, table_expected", + [ + ( + Table({"a": [1,2], "b": [3,4]}), + Table({"d": [1,5], "e": [5,6]}), + ["c"], + ["d"], + "outer", + Table({"a": [1,2,3], "b": [3,4,None], "e": [5, None, None]}), + ), + ( + Table({"a": [1,2], "b": [3,4]}), + Table({"d": [1,5], "e": [5,6]}), + ["a"], + ["d"], + "left", + Table({"a": [1,2], "b": [5,6], "c": [5, None]}), + ), + ( + Table({"a": [1,2], "b": [3,4]}), + Table({"d": [1,5], "e": [5,6]}), + ["a"], + ["d"], + "inner", + Table({"a": [1], "b": [3], "e": [5]}), + ), + ( + Table({"a": [1,2], "b": [3,4]}), + Table({"d": [1,5], "e": [5,6]}), + ["a"], + ["d"], + "right", + Table({"a": [1,3], "b": [3,None], "e": [5,6]}), + ), + ( + Table({"a": [1,2], "b": [3,4], "c": [5,6]}), + Table({"d": [1,5], "e": [5,6],"g": [7,9]}), + ["a", "c"], + ["d", "e"], + "inner", + Table({"a": [1], "b": [3], "c": [5], "g":[7]}), + ), + ( + Table({"a": [1,2], "b": [3,4]}), + Table({"d": [1,5], "e": [5,6]}), + ["b"], + ["e"], + "inner", + Table({"a": [], "b": [], "d": []}), + ), + ( + Table({"a": [1,2], "b": [3,4]}), + Table({"d": [], "e": []}), + ["b"], + [], + "inner", + Table({"a": [], "b": [], "d": []}), + ), + ], + ), +) +def test_join(table_left, table_right, left_names, right_names, mode_, table_expected): + assert table_left.join(table_right, left_names, right_names, mode=mode_) == table_expected From 4fdface23515b20ba2d2956932b55db2934f8fd3 Mon Sep 17 00:00:00 2001 From: grefrathc Date: Fri, 28 Jun 2024 14:21:35 +0200 Subject: [PATCH 03/39] finished ISSUE 745 join --- src/safeds/data/tabular/containers/_table.py | 3 +- .../tabular/containers/_table/test_join.py | 55 ++++++++----------- 2 files changed, 24 insertions(+), 34 deletions(-) diff --git a/src/safeds/data/tabular/containers/_table.py b/src/safeds/data/tabular/containers/_table.py index f728fb3b5..0ec240a68 100644 --- a/src/safeds/data/tabular/containers/_table.py +++ b/src/safeds/data/tabular/containers/_table.py @@ -1707,7 +1707,8 @@ def join(self, rightTable : Table, rightNames: str | list[str], *, mode: Literal["inner", "left", "outer"] = "inner", ) -> Table: - self._data_frame().join(rightTable ) + joined_dataframe = self._data_frame.join(rightTable._data_frame, left_on=left_names, right_on=rightNames, how=mode) + return self._from_polars_data_frame(joined_dataframe) def transform_table(self, fitted_transformer: TableTransformer) -> Table: """ diff --git a/tests/safeds/data/tabular/containers/_table/test_join.py b/tests/safeds/data/tabular/containers/_table/test_join.py index fcafce89b..7336b92d9 100644 --- a/tests/safeds/data/tabular/containers/_table/test_join.py +++ b/tests/safeds/data/tabular/containers/_table/test_join.py @@ -4,66 +4,55 @@ @pytest.mark.parametrize( - ("table_left, table_right, left_names, right_names, mode_, table_expected", + ("table_left", "table_right", "left_names", "right_names", "mode", "table_expected"), [ ( - Table({"a": [1,2], "b": [3,4]}), - Table({"d": [1,5], "e": [5,6]}), - ["c"], + Table({"a": [1, 2], "b": [3, 4]}), + Table({"d": [1, 5], "e": [5, 6]}), + ["a"], ["d"], "outer", - Table({"a": [1,2,3], "b": [3,4,None], "e": [5, None, None]}), + Table({"a": [1, None, 2], "b": [3, None, 4], "d": [1, 5, None], "e" : [5,6, None]}), ), ( - Table({"a": [1,2], "b": [3,4]}), - Table({"d": [1,5], "e": [5,6]}), + Table({"a": [1, 2], "b": [3, 4]}), + Table({"d": [1, 5], "e": [5, 6]}), ["a"], ["d"], "left", - Table({"a": [1,2], "b": [5,6], "c": [5, None]}), + Table({"a": [1, 2], "b": [3, 4], "e": [5, None]}), ), ( - Table({"a": [1,2], "b": [3,4]}), - Table({"d": [1,5], "e": [5,6]}), + Table({"a": [1, 2], "b": [3, 4]}), + Table({"d": [1, 5], "e": [5, 6]}), ["a"], ["d"], "inner", Table({"a": [1], "b": [3], "e": [5]}), ), ( - Table({"a": [1,2], "b": [3,4]}), - Table({"d": [1,5], "e": [5,6]}), - ["a"], - ["d"], - "right", - Table({"a": [1,3], "b": [3,None], "e": [5,6]}), - ), - ( - Table({"a": [1,2], "b": [3,4], "c": [5,6]}), - Table({"d": [1,5], "e": [5,6],"g": [7,9]}), + Table({"a": [1, 2], "b": [3, 4], "c": [5, 6]}), + Table({"d": [1, 5], "e": [5, 6],"g": [7, 9]}), ["a", "c"], ["d", "e"], "inner", Table({"a": [1], "b": [3], "c": [5], "g":[7]}), ), ( - Table({"a": [1,2], "b": [3,4]}), - Table({"d": [1,5], "e": [5,6]}), + Table({"a": [1, 2], "b": [3, 4]}), + Table({"d": [1, 5], "e": [5, 6]}), ["b"], ["e"], "inner", Table({"a": [], "b": [], "d": []}), ), - ( - Table({"a": [1,2], "b": [3,4]}), - Table({"d": [], "e": []}), - ["b"], - [], - "inner", - Table({"a": [], "b": [], "d": []}), - ), ], - ), ) -def test_join(table_left, table_right, left_names, right_names, mode_, table_expected): - assert table_left.join(table_right, left_names, right_names, mode=mode_) == table_expected +def test_join(table_left, table_right, left_names, right_names, mode, table_expected): + print("expected") + print(table_expected) + + print("got") + print(table_left.join(table_right, left_names, right_names, mode=mode)) + + assert table_left.join(table_right, left_names, right_names, mode=mode) == table_expected \ No newline at end of file From 7fb0b7a5999a6fcab6af65f3fcc88c01f9cdb3d0 Mon Sep 17 00:00:00 2001 From: grefrathc Date: Fri, 28 Jun 2024 14:24:39 +0200 Subject: [PATCH 04/39] import warning fixed --- tests/safeds/data/tabular/containers/_table/test_join.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/safeds/data/tabular/containers/_table/test_join.py b/tests/safeds/data/tabular/containers/_table/test_join.py index 7336b92d9..b64a82aef 100644 --- a/tests/safeds/data/tabular/containers/_table/test_join.py +++ b/tests/safeds/data/tabular/containers/_table/test_join.py @@ -1,7 +1,5 @@ -import pytest +import pytest # noqa: I001 from safeds.data.tabular.containers import Table -from safeds.exceptions import ColumnNotFoundError - @pytest.mark.parametrize( ("table_left", "table_right", "left_names", "right_names", "mode", "table_expected"), From 08ffdb2e00d46b54dc0de41952efc9c652828bbd Mon Sep 17 00:00:00 2001 From: grefrathc Date: Fri, 28 Jun 2024 14:31:18 +0200 Subject: [PATCH 05/39] linter problems solved --- src/safeds/data/tabular/containers/_table.py | 6 +++--- tests/safeds/data/tabular/containers/_table/test_join.py | 6 ------ 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/src/safeds/data/tabular/containers/_table.py b/src/safeds/data/tabular/containers/_table.py index 0ec240a68..60e4b0a99 100644 --- a/src/safeds/data/tabular/containers/_table.py +++ b/src/safeds/data/tabular/containers/_table.py @@ -1702,12 +1702,12 @@ def inverse_transform_table(self, fitted_transformer: InvertibleTableTransformer """ return fitted_transformer.inverse_transform(self) - def join(self, rightTable : Table, + def join(self, right_table : Table, left_names: str | list[str], - rightNames: str | list[str], + right_names: str | list[str], *, mode: Literal["inner", "left", "outer"] = "inner", ) -> Table: - joined_dataframe = self._data_frame.join(rightTable._data_frame, left_on=left_names, right_on=rightNames, how=mode) + joined_dataframe = self._data_frame.join(right_table._data_frame, left_on=left_names, right_on=right_names, how=mode) return self._from_polars_data_frame(joined_dataframe) def transform_table(self, fitted_transformer: TableTransformer) -> Table: diff --git a/tests/safeds/data/tabular/containers/_table/test_join.py b/tests/safeds/data/tabular/containers/_table/test_join.py index b64a82aef..f71af9a0e 100644 --- a/tests/safeds/data/tabular/containers/_table/test_join.py +++ b/tests/safeds/data/tabular/containers/_table/test_join.py @@ -47,10 +47,4 @@ ], ) def test_join(table_left, table_right, left_names, right_names, mode, table_expected): - print("expected") - print(table_expected) - - print("got") - print(table_left.join(table_right, left_names, right_names, mode=mode)) - assert table_left.join(table_right, left_names, right_names, mode=mode) == table_expected \ No newline at end of file From 509c07d361b1dabf187abbaa09f51fec6361552f Mon Sep 17 00:00:00 2001 From: grefrathc Date: Fri, 28 Jun 2024 14:52:58 +0200 Subject: [PATCH 06/39] linter problems --- tests/safeds/data/tabular/containers/_table/test_join.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/safeds/data/tabular/containers/_table/test_join.py b/tests/safeds/data/tabular/containers/_table/test_join.py index f71af9a0e..aeeae5ebd 100644 --- a/tests/safeds/data/tabular/containers/_table/test_join.py +++ b/tests/safeds/data/tabular/containers/_table/test_join.py @@ -46,5 +46,5 @@ ), ], ) -def test_join(table_left, table_right, left_names, right_names, mode, table_expected): +def test_join(table_left, table_right, left_names, right_names, mode, table_expected)-> None: assert table_left.join(table_right, left_names, right_names, mode=mode) == table_expected \ No newline at end of file From 440a89f791d258db51a55697829e548fd96e4c0c Mon Sep 17 00:00:00 2001 From: grefrathc Date: Fri, 28 Jun 2024 15:31:45 +0200 Subject: [PATCH 07/39] linter fixes #2 --- tests/safeds/data/tabular/containers/_table/test_join.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/safeds/data/tabular/containers/_table/test_join.py b/tests/safeds/data/tabular/containers/_table/test_join.py index aeeae5ebd..a92fabb2a 100644 --- a/tests/safeds/data/tabular/containers/_table/test_join.py +++ b/tests/safeds/data/tabular/containers/_table/test_join.py @@ -46,5 +46,5 @@ ), ], ) -def test_join(table_left, table_right, left_names, right_names, mode, table_expected)-> None: +def test_join(table_left: Table, table_right: Table, left_names: str | list[str], right_names: str | list[str], mode: str, table_expected: Table)-> None: assert table_left.join(table_right, left_names, right_names, mode=mode) == table_expected \ No newline at end of file From bf990a5d4d4d56e81abf4d1cb9209649314025ca Mon Sep 17 00:00:00 2001 From: grefrathc Date: Fri, 28 Jun 2024 15:43:13 +0200 Subject: [PATCH 08/39] linter fixes #3 --- .../data/tabular/containers/_table/test_join.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/tests/safeds/data/tabular/containers/_table/test_join.py b/tests/safeds/data/tabular/containers/_table/test_join.py index a92fabb2a..c7e31c931 100644 --- a/tests/safeds/data/tabular/containers/_table/test_join.py +++ b/tests/safeds/data/tabular/containers/_table/test_join.py @@ -1,6 +1,7 @@ -import pytest # noqa: I001 +import pytest from safeds.data.tabular.containers import Table + @pytest.mark.parametrize( ("table_left", "table_right", "left_names", "right_names", "mode", "table_expected"), [ @@ -46,5 +47,11 @@ ), ], ) -def test_join(table_left: Table, table_right: Table, left_names: str | list[str], right_names: str | list[str], mode: str, table_expected: Table)-> None: - assert table_left.join(table_right, left_names, right_names, mode=mode) == table_expected \ No newline at end of file +def test_join( + table_left: Table, + table_right: Table, + left_names: list[str], + right_names: list[str], + mode: str, + table_expected: Table, +) -> None: assert table_left.join(table_right, left_names, right_names, mode=mode) == table_expected \ No newline at end of file From 44f32105e714e43c4336afb20a54d9b2425f5386 Mon Sep 17 00:00:00 2001 From: grefrathc Date: Fri, 28 Jun 2024 15:53:06 +0200 Subject: [PATCH 09/39] linter fixes #4 --- tests/safeds/data/tabular/containers/_table/test_join.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/safeds/data/tabular/containers/_table/test_join.py b/tests/safeds/data/tabular/containers/_table/test_join.py index c7e31c931..51e0a358a 100644 --- a/tests/safeds/data/tabular/containers/_table/test_join.py +++ b/tests/safeds/data/tabular/containers/_table/test_join.py @@ -1,3 +1,5 @@ +from typing import Literal + import pytest from safeds.data.tabular.containers import Table @@ -52,6 +54,6 @@ def test_join( table_right: Table, left_names: list[str], right_names: list[str], - mode: str, + mode: Literal["inner", "left", "outer"], table_expected: Table, ) -> None: assert table_left.join(table_right, left_names, right_names, mode=mode) == table_expected \ No newline at end of file From f6ce3184a4849cd79d07ab05cc23f496a0bad7d0 Mon Sep 17 00:00:00 2001 From: megalinter-bot <129584137+megalinter-bot@users.noreply.github.com> Date: Fri, 28 Jun 2024 13:54:35 +0000 Subject: [PATCH 10/39] style: apply automated linter fixes --- src/safeds/data/tabular/containers/_table.py | 17 +++++++++++------ .../classification/_logistic_classifier.py | 11 ++++++----- .../data/tabular/containers/_table/test_join.py | 13 +++++++------ .../classification/test_logistic_classifier.py | 5 +++-- 4 files changed, 27 insertions(+), 19 deletions(-) diff --git a/src/safeds/data/tabular/containers/_table.py b/src/safeds/data/tabular/containers/_table.py index 7a2455bcd..c5da21da3 100644 --- a/src/safeds/data/tabular/containers/_table.py +++ b/src/safeds/data/tabular/containers/_table.py @@ -1708,12 +1708,17 @@ def inverse_transform_table(self, fitted_transformer: InvertibleTableTransformer """ return fitted_transformer.inverse_transform(self) - def join(self, right_table : Table, - left_names: str | list[str], - right_names: str | list[str], - *, mode: Literal["inner", "left", "outer"] = "inner", - ) -> Table: - joined_dataframe = self._data_frame.join(right_table._data_frame, left_on=left_names, right_on=right_names, how=mode) + def join( + self, + right_table: Table, + left_names: str | list[str], + right_names: str | list[str], + *, + mode: Literal["inner", "left", "outer"] = "inner", + ) -> Table: + joined_dataframe = self._data_frame.join( + right_table._data_frame, left_on=left_names, right_on=right_names, how=mode, + ) return self._from_polars_data_frame(joined_dataframe) def transform_table(self, fitted_transformer: TableTransformer) -> Table: diff --git a/src/safeds/ml/classical/classification/_logistic_classifier.py b/src/safeds/ml/classical/classification/_logistic_classifier.py index 0c8e2856b..626e52ea5 100644 --- a/src/safeds/ml/classical/classification/_logistic_classifier.py +++ b/src/safeds/ml/classical/classification/_logistic_classifier.py @@ -17,9 +17,10 @@ class LogisticClassifier(Classifier): # Dunder methods # ------------------------------------------------------------------------------------------------------------------ - def __init__(self, c: float=1.0) -> None: + def __init__(self, c: float = 1.0) -> None: super().__init__() self.c = c + def __hash__(self) -> int: return _structural_hash( super().__hash__(), @@ -30,13 +31,13 @@ def __hash__(self) -> int: # ------------------------------------------------------------------------------------------------------------------ def _clone(self) -> LogisticClassifier: - return LogisticClassifier(c=self.c) - + return LogisticClassifier(c=self.c) + def _get_sklearn_model(self) -> ClassifierMixin: from sklearn.linear_model import LogisticRegression as SklearnLogisticRegression return SklearnLogisticRegression( random_state=_get_random_seed(), n_jobs=-1, - C=self.c, - ) \ No newline at end of file + C=self.c, + ) diff --git a/tests/safeds/data/tabular/containers/_table/test_join.py b/tests/safeds/data/tabular/containers/_table/test_join.py index 51e0a358a..a081b05d2 100644 --- a/tests/safeds/data/tabular/containers/_table/test_join.py +++ b/tests/safeds/data/tabular/containers/_table/test_join.py @@ -5,7 +5,7 @@ @pytest.mark.parametrize( - ("table_left", "table_right", "left_names", "right_names", "mode", "table_expected"), + ("table_left", "table_right", "left_names", "right_names", "mode", "table_expected"), [ ( Table({"a": [1, 2], "b": [3, 4]}), @@ -13,9 +13,9 @@ ["a"], ["d"], "outer", - Table({"a": [1, None, 2], "b": [3, None, 4], "d": [1, 5, None], "e" : [5,6, None]}), + Table({"a": [1, None, 2], "b": [3, None, 4], "d": [1, 5, None], "e": [5, 6, None]}), ), - ( + ( Table({"a": [1, 2], "b": [3, 4]}), Table({"d": [1, 5], "e": [5, 6]}), ["a"], @@ -33,11 +33,11 @@ ), ( Table({"a": [1, 2], "b": [3, 4], "c": [5, 6]}), - Table({"d": [1, 5], "e": [5, 6],"g": [7, 9]}), + Table({"d": [1, 5], "e": [5, 6], "g": [7, 9]}), ["a", "c"], ["d", "e"], "inner", - Table({"a": [1], "b": [3], "c": [5], "g":[7]}), + Table({"a": [1], "b": [3], "c": [5], "g": [7]}), ), ( Table({"a": [1, 2], "b": [3, 4]}), @@ -56,4 +56,5 @@ def test_join( right_names: list[str], mode: Literal["inner", "left", "outer"], table_expected: Table, -) -> None: assert table_left.join(table_right, left_names, right_names, mode=mode) == table_expected \ No newline at end of file +) -> None: + assert table_left.join(table_right, left_names, right_names, mode=mode) == table_expected diff --git a/tests/safeds/ml/classical/classification/test_logistic_classifier.py b/tests/safeds/ml/classical/classification/test_logistic_classifier.py index 768beae22..78c604dad 100644 --- a/tests/safeds/ml/classical/classification/test_logistic_classifier.py +++ b/tests/safeds/ml/classical/classification/test_logistic_classifier.py @@ -9,7 +9,8 @@ def training_set() -> TabularDataset: table = Table({"col1": [1, 2, 3, 4], "col2": [1, 2, 3, 4]}) return table.to_tabular_dataset(target_name="col1") -class TestC: + +class TestC: def test_should_be_passed_to_fitted_model(self, training_set: TabularDataset) -> None: fitted_model = LogisticClassifier(c=2).fit(training_set) assert fitted_model.c == 2 @@ -23,4 +24,4 @@ def test_clone(self, training_set: TabularDataset) -> None: fitted_model = LogisticClassifier(c=2).fit(training_set) cloned_classifier = fitted_model._clone() assert isinstance(cloned_classifier, LogisticClassifier) - assert cloned_classifier.c == fitted_model.c \ No newline at end of file + assert cloned_classifier.c == fitted_model.c From 76561ecbb7e1c25899f611e475d4811277571240 Mon Sep 17 00:00:00 2001 From: megalinter-bot <129584137+megalinter-bot@users.noreply.github.com> Date: Fri, 28 Jun 2024 13:56:03 +0000 Subject: [PATCH 11/39] style: apply automated linter fixes --- src/safeds/data/tabular/containers/_table.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/safeds/data/tabular/containers/_table.py b/src/safeds/data/tabular/containers/_table.py index c5da21da3..aeb03d515 100644 --- a/src/safeds/data/tabular/containers/_table.py +++ b/src/safeds/data/tabular/containers/_table.py @@ -1717,7 +1717,10 @@ def join( mode: Literal["inner", "left", "outer"] = "inner", ) -> Table: joined_dataframe = self._data_frame.join( - right_table._data_frame, left_on=left_names, right_on=right_names, how=mode, + right_table._data_frame, + left_on=left_names, + right_on=right_names, + how=mode, ) return self._from_polars_data_frame(joined_dataframe) From ac6b86283c3a5008d7aac47b74811c706edaf1d1 Mon Sep 17 00:00:00 2001 From: Lars Reimann Date: Sat, 29 Jun 2024 14:58:08 +0200 Subject: [PATCH 12/39] perf: use lazy frames instead of data frames --- src/safeds/data/tabular/containers/_table.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/safeds/data/tabular/containers/_table.py b/src/safeds/data/tabular/containers/_table.py index aeb03d515..95516fc30 100644 --- a/src/safeds/data/tabular/containers/_table.py +++ b/src/safeds/data/tabular/containers/_table.py @@ -1716,13 +1716,14 @@ def join( *, mode: Literal["inner", "left", "outer"] = "inner", ) -> Table: - joined_dataframe = self._data_frame.join( - right_table._data_frame, - left_on=left_names, - right_on=right_names, - how=mode, + return self._from_polars_lazy_frame( + self._lazy_frame.join( + right_table._lazy_frame, + left_on=left_names, + right_on=right_names, + how=mode, + ), ) - return self._from_polars_data_frame(joined_dataframe) def transform_table(self, fitted_transformer: TableTransformer) -> Table: """ From 22faea8620643fce7a8fddddc7de31418c2775a1 Mon Sep 17 00:00:00 2001 From: grefrathc Date: Fri, 5 Jul 2024 15:41:32 +0200 Subject: [PATCH 13/39] documentation for join --- src/safeds/data/tabular/containers/_table.py | 35 ++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/safeds/data/tabular/containers/_table.py b/src/safeds/data/tabular/containers/_table.py index 95516fc30..2278fbb33 100644 --- a/src/safeds/data/tabular/containers/_table.py +++ b/src/safeds/data/tabular/containers/_table.py @@ -1716,6 +1716,41 @@ def join( *, mode: Literal["inner", "left", "outer"] = "inner", ) -> Table: + """ + Join a table with current table and return the result. + + Parameters + ---------- + right_table: + The other table which is to be joined to the current table + left_names: + Name or list of names of collumns from current table on which to join right_table + right_names: + Name or list of names of collumns from right_table on which to join current table + mode: + Specify which type of join you want to use + + Returns + ------- + new_table: + The table with the joined table. + + Examples + -------- + >>> from safeds.data.tabular.containers import Table + >>> table1 = Table({"a": [1, 2], "b": [3, 4]}) + >>> table2 = Table({"d": [1, 5], "e": [5, 6]}) + >>> table1.join(table2, "a", "d", mode = "left") + + +-----+-----+-----+ + | a | b | e | + | --- | --- | --- | + | i64 | i64 | i64 | + +=====+=====|=====| + | 1 | 3 | 5 | + | 2 | 4 | None| + +-----+-----+-----+ + """ return self._from_polars_lazy_frame( self._lazy_frame.join( right_table._lazy_frame, From af60c7ef8461622ddb9e2c600ef6c3cf5ebf3206 Mon Sep 17 00:00:00 2001 From: megalinter-bot <129584137+megalinter-bot@users.noreply.github.com> Date: Fri, 5 Jul 2024 13:43:04 +0000 Subject: [PATCH 14/39] style: apply automated linter fixes --- src/safeds/data/tabular/containers/_table.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/safeds/data/tabular/containers/_table.py b/src/safeds/data/tabular/containers/_table.py index 2278fbb33..cebf6ab0f 100644 --- a/src/safeds/data/tabular/containers/_table.py +++ b/src/safeds/data/tabular/containers/_table.py @@ -1728,7 +1728,7 @@ def join( right_names: Name or list of names of collumns from right_table on which to join current table mode: - Specify which type of join you want to use + Specify which type of join you want to use Returns ------- From 7119cf58ad2d8822ae42e273dbbb760c517eb69a Mon Sep 17 00:00:00 2001 From: grefrathc Date: Fri, 5 Jul 2024 16:09:30 +0200 Subject: [PATCH 15/39] small changes in documentation - join --- src/safeds/data/tabular/containers/_table.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/safeds/data/tabular/containers/_table.py b/src/safeds/data/tabular/containers/_table.py index cebf6ab0f..455d1b3d9 100644 --- a/src/safeds/data/tabular/containers/_table.py +++ b/src/safeds/data/tabular/containers/_table.py @@ -1741,7 +1741,6 @@ def join( >>> table1 = Table({"a": [1, 2], "b": [3, 4]}) >>> table2 = Table({"d": [1, 5], "e": [5, 6]}) >>> table1.join(table2, "a", "d", mode = "left") - +-----+-----+-----+ | a | b | e | | --- | --- | --- | From b54ea09ed1395352705b0b8da5ecfb8689041bd3 Mon Sep 17 00:00:00 2001 From: grefrathc Date: Fri, 5 Jul 2024 16:15:41 +0200 Subject: [PATCH 16/39] test doc join --- src/safeds/data/tabular/containers/_table.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/safeds/data/tabular/containers/_table.py b/src/safeds/data/tabular/containers/_table.py index 455d1b3d9..18bba7d9e 100644 --- a/src/safeds/data/tabular/containers/_table.py +++ b/src/safeds/data/tabular/containers/_table.py @@ -1740,7 +1740,8 @@ def join( >>> from safeds.data.tabular.containers import Table >>> table1 = Table({"a": [1, 2], "b": [3, 4]}) >>> table2 = Table({"d": [1, 5], "e": [5, 6]}) - >>> table1.join(table2, "a", "d", mode = "left") + >>> new_table = table1.join(table2, "a", "d", mode = "left") + >>> print(new_table) +-----+-----+-----+ | a | b | e | | --- | --- | --- | From 2251f9f8e3861dfd47048112a6807c327c7b82db Mon Sep 17 00:00:00 2001 From: grefrathc Date: Fri, 5 Jul 2024 16:26:02 +0200 Subject: [PATCH 17/39] =?UTF-8?q?test=20r=C3=BCckg=C3=A4ngig?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/safeds/data/tabular/containers/_table.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/safeds/data/tabular/containers/_table.py b/src/safeds/data/tabular/containers/_table.py index 18bba7d9e..455d1b3d9 100644 --- a/src/safeds/data/tabular/containers/_table.py +++ b/src/safeds/data/tabular/containers/_table.py @@ -1740,8 +1740,7 @@ def join( >>> from safeds.data.tabular.containers import Table >>> table1 = Table({"a": [1, 2], "b": [3, 4]}) >>> table2 = Table({"d": [1, 5], "e": [5, 6]}) - >>> new_table = table1.join(table2, "a", "d", mode = "left") - >>> print(new_table) + >>> table1.join(table2, "a", "d", mode = "left") +-----+-----+-----+ | a | b | e | | --- | --- | --- | From 9224097ed2e1d475baa05a995a45618d0e312d53 Mon Sep 17 00:00:00 2001 From: Camilla Grefrath Date: Fri, 12 Jul 2024 09:51:32 +0200 Subject: [PATCH 18/39] small changes --- src/safeds/data/tabular/containers/_table.py | 24 ++++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/safeds/data/tabular/containers/_table.py b/src/safeds/data/tabular/containers/_table.py index 455d1b3d9..b7238c155 100644 --- a/src/safeds/data/tabular/containers/_table.py +++ b/src/safeds/data/tabular/containers/_table.py @@ -1717,22 +1717,22 @@ def join( mode: Literal["inner", "left", "outer"] = "inner", ) -> Table: """ - Join a table with current table and return the result. + Join a table with the current table and return the result. Parameters ---------- - right_table: - The other table which is to be joined to the current table - left_names: - Name or list of names of collumns from current table on which to join right_table - right_names: - Name or list of names of collumns from right_table on which to join current table - mode: - Specify which type of join you want to use + right_table: Table + The other table which is to be joined to the current table. + left_names: str or list of str + Name or list of names of columns from the current table on which to join right_table. + right_names: str or list of str + Name or list of names of columns from right_table on which to join the current table. + mode: str + Specify which type of join you want to use. Options include 'inner', 'outer', 'left', 'right'. Returns ------- - new_table: + new_table: Table The table with the joined table. Examples @@ -1740,12 +1740,12 @@ def join( >>> from safeds.data.tabular.containers import Table >>> table1 = Table({"a": [1, 2], "b": [3, 4]}) >>> table2 = Table({"d": [1, 5], "e": [5, 6]}) - >>> table1.join(table2, "a", "d", mode = "left") + >>> table1.join(table2, "a", "d", mode="left") +-----+-----+-----+ | a | b | e | | --- | --- | --- | | i64 | i64 | i64 | - +=====+=====|=====| + +=====+=====+=====+ | 1 | 3 | 5 | | 2 | 4 | None| +-----+-----+-----+ From 4abd576fa23c25e6ca53f2b7a04d352d7a0ea28a Mon Sep 17 00:00:00 2001 From: Camilla Grefrath Date: Fri, 12 Jul 2024 10:40:05 +0200 Subject: [PATCH 19/39] changed None to null in documentation --- src/safeds/data/tabular/containers/_table.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/safeds/data/tabular/containers/_table.py b/src/safeds/data/tabular/containers/_table.py index b7238c155..76c633a23 100644 --- a/src/safeds/data/tabular/containers/_table.py +++ b/src/safeds/data/tabular/containers/_table.py @@ -1747,7 +1747,7 @@ def join( | i64 | i64 | i64 | +=====+=====+=====+ | 1 | 3 | 5 | - | 2 | 4 | None| + | 2 | 4 | null| +-----+-----+-----+ """ return self._from_polars_lazy_frame( From 86a110bf57313ff406ef0c283b2bc41ec1abfbac Mon Sep 17 00:00:00 2001 From: Camilla Grefrath Date: Fri, 12 Jul 2024 10:46:06 +0200 Subject: [PATCH 20/39] formatierung --- src/safeds/data/tabular/containers/_table.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/safeds/data/tabular/containers/_table.py b/src/safeds/data/tabular/containers/_table.py index 76c633a23..be492f48c 100644 --- a/src/safeds/data/tabular/containers/_table.py +++ b/src/safeds/data/tabular/containers/_table.py @@ -1741,14 +1741,14 @@ def join( >>> table1 = Table({"a": [1, 2], "b": [3, 4]}) >>> table2 = Table({"d": [1, 5], "e": [5, 6]}) >>> table1.join(table2, "a", "d", mode="left") - +-----+-----+-----+ - | a | b | e | - | --- | --- | --- | - | i64 | i64 | i64 | - +=====+=====+=====+ - | 1 | 3 | 5 | - | 2 | 4 | null| - +-----+-----+-----+ + +-----+-----+------+ + | a | b | e | + | --- | --- | --- | + | i64 | i64 | i64 | + +==================+ + | 1 | 3 | 5 | + | 2 | 4 | null | + +-----+-----+------+ """ return self._from_polars_lazy_frame( self._lazy_frame.join( From d550f9579fa1b2cd062fdd2d4d454fbde854b77c Mon Sep 17 00:00:00 2001 From: Camilla Grefrath Date: Fri, 12 Jul 2024 11:42:44 +0200 Subject: [PATCH 21/39] Validation --- src/safeds/data/tabular/containers/_table.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/safeds/data/tabular/containers/_table.py b/src/safeds/data/tabular/containers/_table.py index be492f48c..2064c062d 100644 --- a/src/safeds/data/tabular/containers/_table.py +++ b/src/safeds/data/tabular/containers/_table.py @@ -1750,6 +1750,15 @@ def join( | 2 | 4 | null | +-----+-----+------+ """ + + #Validation + _check_columns_exist(self, left_names) + _check_columns_exist(right_table, right_names) + + if len(left_names) != len(right_names): + raise ValueError("The number of columns to join on must be the same in both tables.") + + #Implementation return self._from_polars_lazy_frame( self._lazy_frame.join( right_table._lazy_frame, From 3e96f5566a000cdbf7c944cd9257dda9a24496fb Mon Sep 17 00:00:00 2001 From: Camilla Grefrath Date: Fri, 12 Jul 2024 13:34:46 +0200 Subject: [PATCH 22/39] formatierungsfehler gefixed --- src/safeds/data/tabular/containers/_table.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/safeds/data/tabular/containers/_table.py b/src/safeds/data/tabular/containers/_table.py index 2064c062d..b21cd16e9 100644 --- a/src/safeds/data/tabular/containers/_table.py +++ b/src/safeds/data/tabular/containers/_table.py @@ -1756,7 +1756,7 @@ def join( _check_columns_exist(right_table, right_names) if len(left_names) != len(right_names): - raise ValueError("The number of columns to join on must be the same in both tables.") + raise ValueError("The number of columns to join on must be the same in both tables.") #Implementation return self._from_polars_lazy_frame( From bbb3576bdcb5797f8028b1b92bdef75dedece2e5 Mon Sep 17 00:00:00 2001 From: megalinter-bot <129584137+megalinter-bot@users.noreply.github.com> Date: Fri, 12 Jul 2024 11:36:20 +0000 Subject: [PATCH 23/39] style: apply automated linter fixes --- src/safeds/data/tabular/containers/_table.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/safeds/data/tabular/containers/_table.py b/src/safeds/data/tabular/containers/_table.py index b21cd16e9..5a596d17a 100644 --- a/src/safeds/data/tabular/containers/_table.py +++ b/src/safeds/data/tabular/containers/_table.py @@ -1750,15 +1750,14 @@ def join( | 2 | 4 | null | +-----+-----+------+ """ - - #Validation + # Validation _check_columns_exist(self, left_names) _check_columns_exist(right_table, right_names) if len(left_names) != len(right_names): raise ValueError("The number of columns to join on must be the same in both tables.") - #Implementation + # Implementation return self._from_polars_lazy_frame( self._lazy_frame.join( right_table._lazy_frame, From eab9833b873ff40f28dd8da5f348566f52b5a752 Mon Sep 17 00:00:00 2001 From: Camilla Grefrath Date: Fri, 12 Jul 2024 14:06:36 +0200 Subject: [PATCH 24/39] tests for validation --- .../tabular/containers/_table/test_join.py | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/tests/safeds/data/tabular/containers/_table/test_join.py b/tests/safeds/data/tabular/containers/_table/test_join.py index a081b05d2..32b8aa5f1 100644 --- a/tests/safeds/data/tabular/containers/_table/test_join.py +++ b/tests/safeds/data/tabular/containers/_table/test_join.py @@ -58,3 +58,26 @@ def test_join( table_expected: Table, ) -> None: assert table_left.join(table_right, left_names, right_names, mode=mode) == table_expected + +def test_join_mismatched_columns() -> None: + table_left = Table({"a": [1, 2], "b": [3, 4]}) + table_right = Table({"d": [1, 5], "e": [5, 6]}) + left_names = ["a"] + right_names = ["d", "e"] + mode = "inner" + with pytest.raises(ValueError, match="The number of columns to join on must be the same in both tables."): + table_left.join(table_right, left_names, right_names, mode) + + +def test_join_check_columns_exist() -> None: + table_left = Table({"a": [1, 2], "b": [3, 4]}) + table_right = Table({"d": [1, 5], "e": [5, 6]}) + left_names = ["a", "c"] + right_names = ["d", "e"] + mode = "inner" + with pytest.raises(KeyError): + table_left.join(table_right, left_names, right_names, mode) + left_names = ["a"] + right_names = ["d", "f"] + with pytest.raises(KeyError): + table_left.join(table_right, left_names, right_names, mode) From 099aaff37a7ba1a060e2ff8700d68d21b1ba0836 Mon Sep 17 00:00:00 2001 From: Camilla Grefrath Date: Fri, 12 Jul 2024 14:36:45 +0200 Subject: [PATCH 25/39] correction --- tests/safeds/data/tabular/containers/_table/test_join.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/safeds/data/tabular/containers/_table/test_join.py b/tests/safeds/data/tabular/containers/_table/test_join.py index 32b8aa5f1..6f3cad390 100644 --- a/tests/safeds/data/tabular/containers/_table/test_join.py +++ b/tests/safeds/data/tabular/containers/_table/test_join.py @@ -66,7 +66,7 @@ def test_join_mismatched_columns() -> None: right_names = ["d", "e"] mode = "inner" with pytest.raises(ValueError, match="The number of columns to join on must be the same in both tables."): - table_left.join(table_right, left_names, right_names, mode) + table_left.join(table_right, left_names, right_names, mode=mode) def test_join_check_columns_exist() -> None: @@ -76,8 +76,8 @@ def test_join_check_columns_exist() -> None: right_names = ["d", "e"] mode = "inner" with pytest.raises(KeyError): - table_left.join(table_right, left_names, right_names, mode) + table_left.join(table_right, left_names, right_names, mode=mode) left_names = ["a"] right_names = ["d", "f"] with pytest.raises(KeyError): - table_left.join(table_right, left_names, right_names, mode) + table_left.join(table_right, left_names, right_names, mode=mode) From 55d5d2f07d7176955f151ed3affca32754ca9099 Mon Sep 17 00:00:00 2001 From: Camilla Grefrath Date: Fri, 12 Jul 2024 14:43:11 +0200 Subject: [PATCH 26/39] linter --- tests/safeds/data/tabular/containers/_table/test_join.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/safeds/data/tabular/containers/_table/test_join.py b/tests/safeds/data/tabular/containers/_table/test_join.py index 6f3cad390..05956f4ac 100644 --- a/tests/safeds/data/tabular/containers/_table/test_join.py +++ b/tests/safeds/data/tabular/containers/_table/test_join.py @@ -64,7 +64,7 @@ def test_join_mismatched_columns() -> None: table_right = Table({"d": [1, 5], "e": [5, 6]}) left_names = ["a"] right_names = ["d", "e"] - mode = "inner" + mode = Literal["inner"] with pytest.raises(ValueError, match="The number of columns to join on must be the same in both tables."): table_left.join(table_right, left_names, right_names, mode=mode) @@ -74,7 +74,7 @@ def test_join_check_columns_exist() -> None: table_right = Table({"d": [1, 5], "e": [5, 6]}) left_names = ["a", "c"] right_names = ["d", "e"] - mode = "inner" + mode = Literal["inner"] with pytest.raises(KeyError): table_left.join(table_right, left_names, right_names, mode=mode) left_names = ["a"] From 1e7af57b2d189ad8361785f16248eb89f1c6b677 Mon Sep 17 00:00:00 2001 From: Camilla Grefrath Date: Fri, 12 Jul 2024 14:49:01 +0200 Subject: [PATCH 27/39] literal mode --- tests/safeds/data/tabular/containers/_table/test_join.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/safeds/data/tabular/containers/_table/test_join.py b/tests/safeds/data/tabular/containers/_table/test_join.py index 05956f4ac..2c1ed66f3 100644 --- a/tests/safeds/data/tabular/containers/_table/test_join.py +++ b/tests/safeds/data/tabular/containers/_table/test_join.py @@ -64,7 +64,7 @@ def test_join_mismatched_columns() -> None: table_right = Table({"d": [1, 5], "e": [5, 6]}) left_names = ["a"] right_names = ["d", "e"] - mode = Literal["inner"] + mode = Literal["inner", "left", "outer"] = "inner" with pytest.raises(ValueError, match="The number of columns to join on must be the same in both tables."): table_left.join(table_right, left_names, right_names, mode=mode) @@ -74,7 +74,7 @@ def test_join_check_columns_exist() -> None: table_right = Table({"d": [1, 5], "e": [5, 6]}) left_names = ["a", "c"] right_names = ["d", "e"] - mode = Literal["inner"] + mode = Literal["inner", "left", "outer"] = "inner" with pytest.raises(KeyError): table_left.join(table_right, left_names, right_names, mode=mode) left_names = ["a"] From 2b2962ba5e697b0b84a4008c0f609c249837091a Mon Sep 17 00:00:00 2001 From: Camilla Grefrath Date: Fri, 12 Jul 2024 14:53:04 +0200 Subject: [PATCH 28/39] removed mode --- tests/safeds/data/tabular/containers/_table/test_join.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/tests/safeds/data/tabular/containers/_table/test_join.py b/tests/safeds/data/tabular/containers/_table/test_join.py index 2c1ed66f3..5e8192386 100644 --- a/tests/safeds/data/tabular/containers/_table/test_join.py +++ b/tests/safeds/data/tabular/containers/_table/test_join.py @@ -64,9 +64,8 @@ def test_join_mismatched_columns() -> None: table_right = Table({"d": [1, 5], "e": [5, 6]}) left_names = ["a"] right_names = ["d", "e"] - mode = Literal["inner", "left", "outer"] = "inner" with pytest.raises(ValueError, match="The number of columns to join on must be the same in both tables."): - table_left.join(table_right, left_names, right_names, mode=mode) + table_left.join(table_right, left_names, right_names) def test_join_check_columns_exist() -> None: @@ -74,10 +73,9 @@ def test_join_check_columns_exist() -> None: table_right = Table({"d": [1, 5], "e": [5, 6]}) left_names = ["a", "c"] right_names = ["d", "e"] - mode = Literal["inner", "left", "outer"] = "inner" with pytest.raises(KeyError): - table_left.join(table_right, left_names, right_names, mode=mode) + table_left.join(table_right, left_names, right_names) left_names = ["a"] right_names = ["d", "f"] with pytest.raises(KeyError): - table_left.join(table_right, left_names, right_names, mode=mode) + table_left.join(table_right, left_names, right_names) From 524df738da14197f613e040e148657c456cec81c Mon Sep 17 00:00:00 2001 From: megalinter-bot <129584137+megalinter-bot@users.noreply.github.com> Date: Fri, 12 Jul 2024 12:54:55 +0000 Subject: [PATCH 29/39] style: apply automated linter fixes --- tests/safeds/data/tabular/containers/_table/test_join.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/safeds/data/tabular/containers/_table/test_join.py b/tests/safeds/data/tabular/containers/_table/test_join.py index 5e8192386..52cdd14d5 100644 --- a/tests/safeds/data/tabular/containers/_table/test_join.py +++ b/tests/safeds/data/tabular/containers/_table/test_join.py @@ -59,6 +59,7 @@ def test_join( ) -> None: assert table_left.join(table_right, left_names, right_names, mode=mode) == table_expected + def test_join_mismatched_columns() -> None: table_left = Table({"a": [1, 2], "b": [3, 4]}) table_right = Table({"d": [1, 5], "e": [5, 6]}) From eafb51c243fa9f3afbc07025b9292d4761beac48 Mon Sep 17 00:00:00 2001 From: Camilla Grefrath Date: Fri, 12 Jul 2024 15:06:16 +0200 Subject: [PATCH 30/39] columnNotFound --- tests/safeds/data/tabular/containers/_table/test_join.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/tests/safeds/data/tabular/containers/_table/test_join.py b/tests/safeds/data/tabular/containers/_table/test_join.py index 52cdd14d5..d4a395fa7 100644 --- a/tests/safeds/data/tabular/containers/_table/test_join.py +++ b/tests/safeds/data/tabular/containers/_table/test_join.py @@ -74,9 +74,10 @@ def test_join_check_columns_exist() -> None: table_right = Table({"d": [1, 5], "e": [5, 6]}) left_names = ["a", "c"] right_names = ["d", "e"] - with pytest.raises(KeyError): - table_left.join(table_right, left_names, right_names) + mode: Literal["inner", "left", "outer"] = "inner" + with pytest.raises(ColumnNotFoundError): + table_left.join(table_right, left_names=left_names, right_names=right_names, mode=mode) left_names = ["a"] right_names = ["d", "f"] - with pytest.raises(KeyError): - table_left.join(table_right, left_names, right_names) + with pytest.raises(ColumnNotFoundError): + table_left.join(table_right, left_names=left_names, right_names=right_names, mode=mode) From 10b26fae5a944175c6de709dc84e7598d3673300 Mon Sep 17 00:00:00 2001 From: Camilla Grefrath Date: Fri, 12 Jul 2024 15:11:14 +0200 Subject: [PATCH 31/39] import columnNotFoundError --- tests/safeds/data/tabular/containers/_table/test_join.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/safeds/data/tabular/containers/_table/test_join.py b/tests/safeds/data/tabular/containers/_table/test_join.py index d4a395fa7..927ea3e41 100644 --- a/tests/safeds/data/tabular/containers/_table/test_join.py +++ b/tests/safeds/data/tabular/containers/_table/test_join.py @@ -2,6 +2,7 @@ import pytest from safeds.data.tabular.containers import Table +from safeds.exceptions import ColumnNotFoundError @pytest.mark.parametrize( From 41485127e05b19f3e5cbc2a239b33ba3b8988682 Mon Sep 17 00:00:00 2001 From: megalinter-bot <129584137+megalinter-bot@users.noreply.github.com> Date: Fri, 12 Jul 2024 13:12:45 +0000 Subject: [PATCH 32/39] style: apply automated linter fixes --- tests/safeds/data/tabular/containers/_table/test_join.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/safeds/data/tabular/containers/_table/test_join.py b/tests/safeds/data/tabular/containers/_table/test_join.py index 927ea3e41..93a43c5d6 100644 --- a/tests/safeds/data/tabular/containers/_table/test_join.py +++ b/tests/safeds/data/tabular/containers/_table/test_join.py @@ -2,7 +2,7 @@ import pytest from safeds.data.tabular.containers import Table -from safeds.exceptions import ColumnNotFoundError +from safeds.exceptions import ColumnNotFoundError @pytest.mark.parametrize( From ce8aa8d609323384a45d48b371f07c4e242f1050 Mon Sep 17 00:00:00 2001 From: Camilla Grefrath Date: Thu, 18 Jul 2024 18:52:45 +0200 Subject: [PATCH 33/39] docstrings are not redundant anymore --- src/safeds/data/tabular/containers/_table.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/safeds/data/tabular/containers/_table.py b/src/safeds/data/tabular/containers/_table.py index 5a596d17a..150dbb5dd 100644 --- a/src/safeds/data/tabular/containers/_table.py +++ b/src/safeds/data/tabular/containers/_table.py @@ -1721,18 +1721,18 @@ def join( Parameters ---------- - right_table: Table + right_table: The other table which is to be joined to the current table. - left_names: str or list of str + left_names: Name or list of names of columns from the current table on which to join right_table. - right_names: str or list of str + right_names: Name or list of names of columns from right_table on which to join the current table. - mode: str + mode: Specify which type of join you want to use. Options include 'inner', 'outer', 'left', 'right'. Returns ------- - new_table: Table + new_table: The table with the joined table. Examples From 57abceef920d08968ace6c16f852ed0f96d64cc8 Mon Sep 17 00:00:00 2001 From: Camilla Grefrath Date: Thu, 18 Jul 2024 19:02:29 +0200 Subject: [PATCH 34/39] tests for check column exists --- .../tabular/containers/_table/test_join.py | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/tests/safeds/data/tabular/containers/_table/test_join.py b/tests/safeds/data/tabular/containers/_table/test_join.py index 93a43c5d6..d4b7e5109 100644 --- a/tests/safeds/data/tabular/containers/_table/test_join.py +++ b/tests/safeds/data/tabular/containers/_table/test_join.py @@ -82,3 +82,34 @@ def test_join_check_columns_exist() -> None: right_names = ["d", "f"] with pytest.raises(ColumnNotFoundError): table_left.join(table_right, left_names=left_names, right_names=right_names, mode=mode) + +def test_check_columns_exist() -> None: + table = Table({"a": [1, 2], "b": [3, 4]}) + _check_columns_exist(table, ["a"]) # Should not raise + _check_columns_exist(table, ["a", "b"]) # Should not raise + with pytest.raises(ColumnNotFoundError): + _check_columns_exist(table, ["c"]) # Should raise + +def test_check_columns_exist_in_join() -> None: + table_left = Table({"a": [1, 2], "b": [3, 4]}) + table_right = Table({"d": [1, 5], "e": [5, 6]}) + left_names = ["a"] + right_names = ["d"] + mode: Literal["inner", "left", "outer"] = "inner" + table_left.join(table_right, left_names=left_names, right_names=right_names, mode=mode) # Should not raise + +def test_invalid_column_name_in_join() -> None: + table_left = Table({"a": [1, 2], "b": [3, 4]}) + table_right = Table({"d": [1, 5], "e": [5, 6]}) + left_names = ["z"] # Invalid column + right_names = ["d"] + mode: Literal["inner", "left", "outer"] = "inner" + with pytest.raises(ColumnNotFoundError): + table_left.join(table_right, left_names=left_names, right_names=right_names, mode=mode) + +def test_check_columns_exist_edge_cases() -> None: + table = Table({"a": [1, 2], "b": [3, 4]}) + with pytest.raises(ColumnNotFoundError): + _check_columns_exist(table, []) # Empty column list + with pytest.raises(ColumnNotFoundError): + _check_columns_exist(table, ["a", "b", "c"]) # Mixed valid and invalid columns From de5de4c64f984d899bfff0421c22de959beeb848 Mon Sep 17 00:00:00 2001 From: Camilla Grefrath Date: Thu, 18 Jul 2024 19:12:30 +0200 Subject: [PATCH 35/39] tests were already there so we deleted the redundant tests --- .../tabular/containers/_table/test_join.py | 33 +------------------ 1 file changed, 1 insertion(+), 32 deletions(-) diff --git a/tests/safeds/data/tabular/containers/_table/test_join.py b/tests/safeds/data/tabular/containers/_table/test_join.py index d4b7e5109..aa6f8e8ba 100644 --- a/tests/safeds/data/tabular/containers/_table/test_join.py +++ b/tests/safeds/data/tabular/containers/_table/test_join.py @@ -81,35 +81,4 @@ def test_join_check_columns_exist() -> None: left_names = ["a"] right_names = ["d", "f"] with pytest.raises(ColumnNotFoundError): - table_left.join(table_right, left_names=left_names, right_names=right_names, mode=mode) - -def test_check_columns_exist() -> None: - table = Table({"a": [1, 2], "b": [3, 4]}) - _check_columns_exist(table, ["a"]) # Should not raise - _check_columns_exist(table, ["a", "b"]) # Should not raise - with pytest.raises(ColumnNotFoundError): - _check_columns_exist(table, ["c"]) # Should raise - -def test_check_columns_exist_in_join() -> None: - table_left = Table({"a": [1, 2], "b": [3, 4]}) - table_right = Table({"d": [1, 5], "e": [5, 6]}) - left_names = ["a"] - right_names = ["d"] - mode: Literal["inner", "left", "outer"] = "inner" - table_left.join(table_right, left_names=left_names, right_names=right_names, mode=mode) # Should not raise - -def test_invalid_column_name_in_join() -> None: - table_left = Table({"a": [1, 2], "b": [3, 4]}) - table_right = Table({"d": [1, 5], "e": [5, 6]}) - left_names = ["z"] # Invalid column - right_names = ["d"] - mode: Literal["inner", "left", "outer"] = "inner" - with pytest.raises(ColumnNotFoundError): - table_left.join(table_right, left_names=left_names, right_names=right_names, mode=mode) - -def test_check_columns_exist_edge_cases() -> None: - table = Table({"a": [1, 2], "b": [3, 4]}) - with pytest.raises(ColumnNotFoundError): - _check_columns_exist(table, []) # Empty column list - with pytest.raises(ColumnNotFoundError): - _check_columns_exist(table, ["a", "b", "c"]) # Mixed valid and invalid columns + table_left.join(table_right, left_names=left_names, right_names=right_names, mode=mode) \ No newline at end of file From 2bf76fcf034e32a9ae5443f46d5361364c3e574c Mon Sep 17 00:00:00 2001 From: megalinter-bot <129584137+megalinter-bot@users.noreply.github.com> Date: Thu, 18 Jul 2024 17:14:10 +0000 Subject: [PATCH 36/39] style: apply automated linter fixes --- tests/safeds/data/tabular/containers/_table/test_join.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/safeds/data/tabular/containers/_table/test_join.py b/tests/safeds/data/tabular/containers/_table/test_join.py index aa6f8e8ba..93a43c5d6 100644 --- a/tests/safeds/data/tabular/containers/_table/test_join.py +++ b/tests/safeds/data/tabular/containers/_table/test_join.py @@ -81,4 +81,4 @@ def test_join_check_columns_exist() -> None: left_names = ["a"] right_names = ["d", "f"] with pytest.raises(ColumnNotFoundError): - table_left.join(table_right, left_names=left_names, right_names=right_names, mode=mode) \ No newline at end of file + table_left.join(table_right, left_names=left_names, right_names=right_names, mode=mode) From 0d5edc6176bf3b1456bdf0f3d18f9b14bf34e685 Mon Sep 17 00:00:00 2001 From: Lars Reimann Date: Fri, 19 Jul 2024 14:14:53 +0200 Subject: [PATCH 37/39] test: rename tests to match convention --- tests/safeds/data/tabular/containers/_table/test_join.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/safeds/data/tabular/containers/_table/test_join.py b/tests/safeds/data/tabular/containers/_table/test_join.py index 93a43c5d6..687dfe36c 100644 --- a/tests/safeds/data/tabular/containers/_table/test_join.py +++ b/tests/safeds/data/tabular/containers/_table/test_join.py @@ -50,7 +50,7 @@ ), ], ) -def test_join( +def test_should_join_two_tables( table_left: Table, table_right: Table, left_names: list[str], @@ -61,7 +61,7 @@ def test_join( assert table_left.join(table_right, left_names, right_names, mode=mode) == table_expected -def test_join_mismatched_columns() -> None: +def test_should_raise_if_columns_are_mismatched() -> None: table_left = Table({"a": [1, 2], "b": [3, 4]}) table_right = Table({"d": [1, 5], "e": [5, 6]}) left_names = ["a"] @@ -70,7 +70,7 @@ def test_join_mismatched_columns() -> None: table_left.join(table_right, left_names, right_names) -def test_join_check_columns_exist() -> None: +def test_should_raise_if_columns_are_missing() -> None: table_left = Table({"a": [1, 2], "b": [3, 4]}) table_right = Table({"d": [1, 5], "e": [5, 6]}) left_names = ["a", "c"] From f65f20e4b5b856d61b89844035c190d99341ffbd Mon Sep 17 00:00:00 2001 From: Lars Reimann Date: Fri, 19 Jul 2024 14:18:58 +0200 Subject: [PATCH 38/39] test: parametrize test --- .../tabular/containers/_table/test_join.py | 29 ++++++++++++------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/tests/safeds/data/tabular/containers/_table/test_join.py b/tests/safeds/data/tabular/containers/_table/test_join.py index 687dfe36c..a8e818732 100644 --- a/tests/safeds/data/tabular/containers/_table/test_join.py +++ b/tests/safeds/data/tabular/containers/_table/test_join.py @@ -70,15 +70,22 @@ def test_should_raise_if_columns_are_mismatched() -> None: table_left.join(table_right, left_names, right_names) -def test_should_raise_if_columns_are_missing() -> None: - table_left = Table({"a": [1, 2], "b": [3, 4]}) - table_right = Table({"d": [1, 5], "e": [5, 6]}) - left_names = ["a", "c"] - right_names = ["d", "e"] - mode: Literal["inner", "left", "outer"] = "inner" - with pytest.raises(ColumnNotFoundError): - table_left.join(table_right, left_names=left_names, right_names=right_names, mode=mode) - left_names = ["a"] - right_names = ["d", "f"] +@pytest.mark.parametrize( + ("table_left", "table_right", "left_names", "right_names"), + [ + (Table({"a": [1, 2], "b": [3, 4]}), Table({"d": [1, 5], "e": [5, 6]}), ["c"], ["d"]), + (Table({"a": [1, 2], "b": [3, 4]}), Table({"d": [1, 5], "e": [5, 6]}), ["a"], ["f"]), + ], + id=[ + "wrong_left_name", + "wrong_right_name", + ], +) +def test_should_raise_if_columns_are_missing( + table_left: Table, + table_right: Table, + left_names: list[str], + right_names: list[str], +) -> None: with pytest.raises(ColumnNotFoundError): - table_left.join(table_right, left_names=left_names, right_names=right_names, mode=mode) + table_left.join(table_right, left_names=left_names, right_names=right_names) From 172bbb84b222644e60c56db8cd2216799c93cb2f Mon Sep 17 00:00:00 2001 From: Lars Reimann Date: Fri, 19 Jul 2024 14:41:16 +0200 Subject: [PATCH 39/39] test: parametrize test --- tests/safeds/data/tabular/containers/_table/test_join.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/safeds/data/tabular/containers/_table/test_join.py b/tests/safeds/data/tabular/containers/_table/test_join.py index a8e818732..1a1aec200 100644 --- a/tests/safeds/data/tabular/containers/_table/test_join.py +++ b/tests/safeds/data/tabular/containers/_table/test_join.py @@ -76,7 +76,7 @@ def test_should_raise_if_columns_are_mismatched() -> None: (Table({"a": [1, 2], "b": [3, 4]}), Table({"d": [1, 5], "e": [5, 6]}), ["c"], ["d"]), (Table({"a": [1, 2], "b": [3, 4]}), Table({"d": [1, 5], "e": [5, 6]}), ["a"], ["f"]), ], - id=[ + ids=[ "wrong_left_name", "wrong_right_name", ],