Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Maintain tagging in methods inherited from Table class #332

Merged
Merged
Show file tree
Hide file tree
Changes from 43 commits
Commits
Show all changes
198 commits
Select commit Hold shift + click to select a range
0a5c611
Add exception classes
zzril May 29, 2023
615d10a
style: apply automated linter fixes
megalinter-bot May 29, 2023
2ab4c93
Add implementation for add_column
zzril May 29, 2023
1183c3e
Add test for overriden add_columns method
zzril May 29, 2023
09110ca
Add __init.py__ to _tagged_table test directory
zzril May 29, 2023
ce347fe
Add return type annotations
zzril May 29, 2023
24c6aef
style: apply automated linter fixes
megalinter-bot May 29, 2023
dc6de53
style: apply automated linter fixes
megalinter-bot May 29, 2023
fd5e6ab
Add specific tests for features and target
zzril May 29, 2023
e6da4d2
Merge branch '58-in-taggedtable-override-methods-of-table-that-return…
zzril May 29, 2023
5370f9f
Add add_columns implementation
zzril May 29, 2023
6b2846b
Use public getter to access target column
zzril May 29, 2023
46aa81a
Add more implementations
zzril May 29, 2023
f9f302c
style: apply automated linter fixes
megalinter-bot May 29, 2023
18d37fb
Start keep_only_columns implementation
zzril May 29, 2023
30b85b6
style: apply automated linter fixes
megalinter-bot May 29, 2023
6a637a7
Start remove_columns implementation
zzril May 29, 2023
4f0fc80
Override remove_columns_with_missing_values
zzril May 29, 2023
c02a34a
Fix typo in todo comment
zzril May 29, 2023
ab44cf8
Catch correct exception
zzril May 29, 2023
e6621f3
Add tests
zzril May 29, 2023
973f907
style: apply automated linter fixes
megalinter-bot May 29, 2023
c8ecbef
Add test for ColumnIsTaggedError
zzril May 29, 2023
9f9e03a
style: apply automated linter fixes
megalinter-bot May 29, 2023
348ab72
style: apply automated linter fixes
megalinter-bot May 29, 2023
f111adf
Use try-catch for remove_columns
zzril May 29, 2023
eae61a9
Implement remove_columns_with_non_numerical_values
zzril May 29, 2023
2a0fac8
Implement more row removing functions
zzril May 29, 2023
f691f5b
Implement rename_column and add tests
zzril May 29, 2023
20b00de
style: apply automated linter fixes
megalinter-bot May 29, 2023
e4f9b19
Add test for filter_rows
zzril May 29, 2023
28474b8
style: apply automated linter fixes
megalinter-bot May 29, 2023
d71b572
Implement replace_column and parametrize tests
zzril May 29, 2023
ce68cc9
style: apply automated linter fixes
megalinter-bot May 29, 2023
c59f552
style: apply automated linter fixes
megalinter-bot May 29, 2023
d42a9b4
Implement shuffle_rows
zzril May 30, 2023
4b0a713
style: apply automated linter fixes
megalinter-bot May 30, 2023
1ccf1dd
Override slice_rows
zzril May 30, 2023
2d28696
Override sort_columns
zzril May 30, 2023
5df6fba
style: apply automated linter fixes
megalinter-bot May 30, 2023
34376ce
Override sort_rows
zzril May 30, 2023
4f1b19f
style: apply automated linter fixes
megalinter-bot May 30, 2023
20a4856
Override transform_column
zzril May 30, 2023
9dfab62
Merge branch 'main' into 58-in-taggedtable-override-methods-of-table-…
zzril Jun 1, 2023
4ad330a
style: Drop unused keyword parameters
zzril Jun 1, 2023
71ed46a
Merge branch 'main' into 58-in-taggedtable-override-methods-of-table-…
zzril Jun 1, 2023
319f44f
feat: Override transform_table
zzril Jun 1, 2023
0a23638
Move import to type checking block
zzril Jun 1, 2023
af72037
Merge branch 'main' into 58-in-taggedtable-override-methods-of-table-…
zzril Jun 1, 2023
ab40aaa
style: apply automated linter fixes
megalinter-bot Jun 1, 2023
b42a8a9
style: apply automated linter fixes
megalinter-bot Jun 1, 2023
131bf7a
feat: add helper asserting TaggedTables are equal
zzril Jun 1, 2023
9b7919d
feat: Override inverse_transform_table
zzril Jun 1, 2023
1984707
style: apply automated linter fixes
megalinter-bot Jun 1, 2023
8925a17
docs: remove quotes in console examples
zzril Jun 1, 2023
f682b6a
Merge branch '58-in-taggedtable-override-methods-of-table-that-return…
zzril Jun 1, 2023
2bf77fa
docs: fix indentation in transform_table
zzril Jun 1, 2023
ec37d56
docs: fix indentation in console examples
zzril Jun 1, 2023
b03aa01
Merge branch 'main' into 58-in-taggedtable-override-methods-of-table-…
zzril Jun 2, 2023
4a30ca2
Merge branch 'main' into 58-in-taggedtable-override-methods-of-table-…
zzril Jun 6, 2023
7619a0f
Merge branch 'main' into 58-in-taggedtable-override-methods-of-table-…
zzril Jun 8, 2023
5545621
style: apply automated linter fixes
megalinter-bot Jun 8, 2023
22b57b6
Merge branch 'main' into 58-in-taggedtable-override-methods-of-table-…
zzril Jun 9, 2023
3f00be6
Rename ColumnIsTaggedError to ColumnIsTargetError
zzril Jun 9, 2023
e5936b8
Document exceptions in parent class
zzril Jun 9, 2023
0d231f0
Override remove_columns
zzril Jun 9, 2023
599f8b9
Merge branch 'main' into 58-in-taggedtable-override-methods-of-table-…
zzril Jun 9, 2023
0cdb4e1
Merge branch 'main' into 58-in-taggedtable-override-methods-of-table-…
zzril Jun 9, 2023
7d5a574
Adapt tests to new replace_column signature
zzril Jun 9, 2023
d846885
style: apply automated linter fixes
megalinter-bot Jun 9, 2023
23cb5f8
style: apply automated linter fixes
megalinter-bot Jun 9, 2023
e3bcac2
Add replace_column testcases that would throw
zzril Jun 9, 2023
8cc8099
Merge branch '58-in-taggedtable-override-methods-of-table-that-return…
zzril Jun 9, 2023
11fd2f6
style: apply automated linter fixes
megalinter-bot Jun 9, 2023
d219a4f
style: apply automated linter fixes
megalinter-bot Jun 9, 2023
eb09acc
feat: add remove_target_column to TaggedTable
zzril Jun 9, 2023
1809eb5
style: apply automated linter fixes
megalinter-bot Jun 9, 2023
925c100
Make test_classifier.py use remove_target_column
zzril Jun 9, 2023
b44e8a4
Make test_regressor.py use remove_target_column
zzril Jun 9, 2023
3ce32f7
Override remove_column
zzril Jun 9, 2023
ffe64f5
Comment-out currently unreachable lines
zzril Jun 9, 2023
de0dc57
Adapt signature of keep_only_columns
zzril Jun 9, 2023
a1d7fb1
style: Drop solved todo comment
zzril Jun 9, 2023
adbb9bd
style: drop unneeded format string
zzril Jun 9, 2023
1dd8256
Fix comments
zzril Jun 9, 2023
a3f431b
Add instanceof check to util_sklearn methods
zzril Jun 9, 2023
f08a8af
Do type check as early as possible
zzril Jun 9, 2023
f905b32
Merge branch 'main' into 58-in-taggedtable-override-methods-of-table-…
zzril Jun 11, 2023
bdca892
Merge branch 'main' into 58-in-taggedtable-override-methods-of-table-…
zzril Jun 13, 2023
d28763f
Merge branch 'main' into 58-in-taggedtable-override-methods-of-table-…
zzril Jun 16, 2023
ed4baa1
Merge branch 'main' into 58-in-taggedtable-override-methods-of-table-…
zzril Jun 23, 2023
6507824
Add to_table method to TaggedTable class
zzril Jun 23, 2023
76ed6ad
Drop remove_target_column method from TaggedTable
zzril Jun 23, 2023
c4185c9
Add test for to_table
zzril Jun 23, 2023
5696f91
style: apply automated linter fixes
megalinter-bot Jun 23, 2023
68dfc00
Make to_table an instance method
zzril Jun 23, 2023
8854c54
Merge branch '58-in-taggedtable-override-methods-of-table-that-return…
zzril Jun 23, 2023
8af1153
Remove method calls on semi-initialized table
zzril Jun 23, 2023
94b0a18
Add type check to from_table method
zzril Jun 23, 2023
6cb25c5
Implement keep_only_columns
zzril Jun 23, 2023
1e21156
Merge branch 'main' into 58-in-taggedtable-override-methods-of-table-…
zzril Jun 23, 2023
db1a22e
Merge branch 'main' into 58-in-taggedtable-override-methods-of-table-…
zzril Jun 23, 2023
636a4d0
Add as_table method
zzril Jun 23, 2023
0e0e8f6
style: apply automated linter fixes
megalinter-bot Jun 23, 2023
67f694c
Rename to _as_table
zzril Jun 23, 2023
e722c91
Merge branch '58-in-taggedtable-override-methods-of-table-that-return…
zzril Jun 23, 2023
813ca3f
Fix call in OneHotEncoder
zzril Jun 23, 2023
cbea9c3
style: apply automated linter fixes
megalinter-bot Jun 23, 2023
0d3eae1
Fix next call in OneHotEncoder
zzril Jun 23, 2023
32c427c
Merge branch '58-in-taggedtable-override-methods-of-table-that-return…
zzril Jun 23, 2023
ddeebd3
Fix last call in OneHotEncoder
zzril Jun 23, 2023
1a9ece7
Add generic exceptions in docstrings of superclass
zzril Jun 23, 2023
256ba64
Add tests for keep_only_columns
zzril Jun 23, 2023
85125d7
style: apply automated linter fixes
megalinter-bot Jun 23, 2023
871460b
style: apply automated linter fixes
megalinter-bot Jun 23, 2023
66bcf8e
Fix name of test function
zzril Jun 23, 2023
01e09c8
Merge branch 'main' into 58-in-taggedtable-override-methods-of-table-…
zzril Jun 23, 2023
e0f7587
feat: Added methods `TaggedTable.add_column_as_feature` and `Taggedta…
Marsmaennchen221 Jun 23, 2023
ed531d3
Merge branch '58-in-taggedtable-override-methods-of-table-that-return…
Marsmaennchen221 Jun 23, 2023
8e25c86
test: Corrected tests after merge
Marsmaennchen221 Jun 23, 2023
851a83a
Merge branch 'main' into 58-in-taggedtable-override-methods-of-table-…
zzril Jun 23, 2023
1ca61c7
Apply suggestions from code review
zzril Jun 23, 2023
b29be63
refactor: Added changes for linters
Marsmaennchen221 Jun 23, 2023
8d335a3
refactor: Just testing if the linter will accept this
Marsmaennchen221 Jun 23, 2023
65e0e72
refactor: The linter should be happy now
Marsmaennchen221 Jun 23, 2023
bf42687
style: apply automated linter fixes
megalinter-bot Jun 23, 2023
da93e49
style: apply automated linter fixes
megalinter-bot Jun 23, 2023
e3a8ce5
Add tests for remove_column
zzril Jun 23, 2023
6bfad10
Merge branch '58-in-taggedtable-override-methods-of-table-that-return…
zzril Jun 23, 2023
90a7255
Merge branch 'main' into 58-in-taggedtable-override-methods-of-table-…
Marsmaennchen221 Jun 23, 2023
9c2c750
style: apply automated linter fixes
megalinter-bot Jun 23, 2023
c4c00e1
Merge branch 'main' of https://github.com/Safe-DS/Stdlib into 58-in-t…
Marsmaennchen221 Jun 23, 2023
48ed202
Merge branch 'main' into 58-in-taggedtable-override-methods-of-table-…
zzril Jun 30, 2023
3018b51
Merge branch 'main' into 58-in-taggedtable-override-methods-of-table-…
zzril Jun 30, 2023
7437be1
docs: Removed unnecessary empty lines in comment
Marsmaennchen221 Jun 30, 2023
24dc166
Merge branch '58-in-taggedtable-override-methods-of-table-that-return…
Marsmaennchen221 Jun 30, 2023
75b3a23
feat: Using a table instead of super in `TaggedTable.__init__` becaus…
Marsmaennchen221 Jun 30, 2023
7c366dc
Fix _as_table
zzril Jun 30, 2023
a31769d
style: apply automated linter fixes
megalinter-bot Jun 30, 2023
711943e
Merge branch 'main' into 58-in-taggedtable-override-methods-of-table-…
zzril Jun 30, 2023
f7219d5
Update tests for sort_rows
zzril Jun 30, 2023
c01f208
Update inplace test
zzril Jun 30, 2023
1ffe1c9
Update test for shuffle_rows
zzril Jun 30, 2023
0af1b01
style: apply automated linter fixes
megalinter-bot Jun 30, 2023
f38ccdc
Update tests for replace_column
zzril Jun 30, 2023
7b23f4d
Merge branch '58-in-taggedtable-override-methods-of-table-that-return…
zzril Jun 30, 2023
e49ff3d
test: Moved tests from `test_tagged_table.py` to their own files in _…
Marsmaennchen221 Jun 30, 2023
6eac3fb
Merge branch '58-in-taggedtable-override-methods-of-table-that-return…
Marsmaennchen221 Jun 30, 2023
d50a943
Update test_rename_column.py
zzril Jun 30, 2023
72d8907
Merge branch '58-in-taggedtable-override-methods-of-table-that-return…
zzril Jun 30, 2023
a4068c6
Merge branch 'main' into 58-in-taggedtable-override-methods-of-table-…
zzril Jun 30, 2023
cc26bdf
style: apply automated linter fixes
megalinter-bot Jun 30, 2023
4c83491
style: apply automated linter fixes
megalinter-bot Jun 30, 2023
1562ba9
Merge branch 'main' into 58-in-taggedtable-override-methods-of-table-…
zzril Jul 6, 2023
cff102f
Merge branch 'main' into 58-in-taggedtable-override-methods-of-table-…
zzril Jul 6, 2023
c4d212e
Merge branch 'main' into 58-in-taggedtable-override-methods-of-table-…
zzril Jul 7, 2023
447dd82
Update test_remove_rows_with_outliers.py
zzril Jul 7, 2023
1016eef
style: apply automated linter fixes
megalinter-bot Jul 7, 2023
31c83f3
Add new testcase to test_remove_rows_with_outliers
zzril Jul 7, 2023
192d789
Merge branch '58-in-taggedtable-override-methods-of-table-that-return…
zzril Jul 7, 2023
ae7a105
style: apply automated linter fixes
megalinter-bot Jul 7, 2023
5e3c1d4
Update test_remove_rows_with_missing_values.py
zzril Jul 7, 2023
b352d53
Update test_remove_duplicate_rows.py
zzril Jul 7, 2023
8ef1442
Parametrize non_numerical tests
zzril Jul 7, 2023
6cffec3
Add testcases for non_numerical tests
zzril Jul 7, 2023
9212532
Update error test for non_numerical
zzril Jul 7, 2023
6ea0147
Update test_remove_columns_with_missing_values.py
zzril Jul 7, 2023
121f2a1
Merge branch '58-in-taggedtable-override-methods-of-table-that-return…
zzril Jul 7, 2023
70f9e9b
style: apply automated linter fixes
megalinter-bot Jul 7, 2023
09bbadb
Add testcases for remove_columns
zzril Jul 7, 2023
0c38d5a
Merge branch '58-in-taggedtable-override-methods-of-table-that-return…
zzril Jul 7, 2023
aecf49a
style: apply automated linter fixes
megalinter-bot Jul 7, 2023
03efb3c
Add testcases for error in remove_columns
zzril Jul 7, 2023
1313f2a
Merge branch '58-in-taggedtable-override-methods-of-table-that-return…
zzril Jul 7, 2023
8e7f365
style: apply automated linter fixes
megalinter-bot Jul 7, 2023
bffa974
Fix empty list case in test_remove_columns.py
zzril Jul 7, 2023
ec945cf
Merge branch '58-in-taggedtable-override-methods-of-table-that-return…
zzril Jul 7, 2023
0e761d4
Merge branch 'main' into 58-in-taggedtable-override-methods-of-table-…
zzril Jul 7, 2023
7fb14a8
style: apply automated linter fixes
megalinter-bot Jul 7, 2023
af7a716
test: added parametrization to tests for `TaggedTable` and finished t…
Marsmaennchen221 Jul 7, 2023
3f8f816
Merge branch '58-in-taggedtable-override-methods-of-table-that-return…
Marsmaennchen221 Jul 7, 2023
afbefab
style: apply automated linter fixes
megalinter-bot Jul 7, 2023
3c6feb0
style: apply automated linter fixes
megalinter-bot Jul 7, 2023
a00f440
feat: Improved error messages for `TaggedTable.remove_columns`, `Tagg…
Marsmaennchen221 Jul 7, 2023
7c36d64
Merge branch '58-in-taggedtable-override-methods-of-table-that-return…
Marsmaennchen221 Jul 7, 2023
c3bf71d
style: apply automated linter fixes
megalinter-bot Jul 7, 2023
f7a8c6f
style: apply automated linter fixes
megalinter-bot Jul 7, 2023
a9e5851
Merge branch 'main' into 58-in-taggedtable-override-methods-of-table-…
zzril Jul 7, 2023
0d159c2
Apply suggestions from code review
Marsmaennchen221 Jul 7, 2023
168891f
Merge branch 'main' into 58-in-taggedtable-override-methods-of-table-…
zzril Jul 7, 2023
6e65b12
Update src/safeds/data/tabular/containers/_tagged_table.py
zzril Jul 8, 2023
d590824
Update tests/safeds/data/tabular/containers/_table/_tagged_table/test…
zzril Jul 8, 2023
fd2e1e3
Update tests/safeds/data/tabular/containers/_table/_tagged_table/test…
zzril Jul 8, 2023
d0f2451
Improve testcase naming in test_features.py
zzril Jul 8, 2023
ea1a46c
Update src/safeds/data/tabular/containers/_tagged_table.py
zzril Jul 8, 2023
f37586b
style: apply automated linter fixes
megalinter-bot Jul 8, 2023
0db7131
Merge branch 'main' into 58-in-taggedtable-override-methods-of-table-…
zzril Jul 8, 2023
ff3782b
Update src/safeds/data/tabular/containers/_tagged_table.py
zzril Jul 8, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
460 changes: 458 additions & 2 deletions src/safeds/data/tabular/containers/_tagged_table.py

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions src/safeds/exceptions/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
"""Custom exceptions that can be raised by Safe-DS."""

from safeds.exceptions._data import (
ColumnIsTaggedError,
ColumnLengthMismatchError,
ColumnSizeError,
DuplicateColumnNameError,
IllegalSchemaModificationError,
IndexOutOfBoundsError,
NonNumericColumnError,
SchemaMismatchError,
Expand Down Expand Up @@ -33,6 +35,8 @@
"UnknownColumnNameError",
"ValueNotPresentWhenFittedError",
"WrongFileExtensionError",
"IllegalSchemaModificationError",
"ColumnIsTaggedError",
# ML exceptions
"DatasetContainsTargetError",
"DatasetMissesFeaturesError",
Expand Down
14 changes: 14 additions & 0 deletions src/safeds/exceptions/_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,17 @@ def __init__(self, file: str | Path, file_extension: str | list[str]) -> None:
f" {file_extension}"
),
)


class IllegalSchemaModificationError(Exception):
"""Exception raised when modifying the schema in a way that is not consistent with the subclass's requirements."""
Marsmaennchen221 marked this conversation as resolved.
Show resolved Hide resolved

def __init__(self, msg: str) -> None:
super().__init__(f"Illegal schema modification: {msg}")


class ColumnIsTaggedError(IllegalSchemaModificationError):
"""Exception raised in overriden methods of the Table class when removing tagged Columns from a TaggedTable."""

def __init__(self, column_name: str) -> None:
super().__init__(f'Column "{column_name}" is tagged and cannot be removed.')
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from safeds.data.tabular.containers import Column, TaggedTable


def test_should_add_column() -> None:
table = TaggedTable(
{
"feature_1": [0, 1, 2],
"target": [3, 4, 5],
},
"target",
None,
)
col = Column("feature_2", [6, 7, 8])
new_table = table.add_column(col)
expected = TaggedTable(
{
"feature_1": [0, 1, 2],
"target": [3, 4, 5],
"feature_2": [6, 7, 8],
},
"target",
None,
)
assert new_table.schema == expected.schema
assert new_table.features == expected.features
assert new_table.target == expected.target
assert new_table == expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from safeds.data.tabular.containers import Column, TaggedTable


def test_should_add_columns() -> None:
table = TaggedTable(
{
"feature_1": [0, 1, 2],
"target": [3, 4, 5],
},
"target",
None,
)
cols = [
Column("feature_2", [6, 7, 8]),
Column("feature_3", [9, 6, 3]),
]
new_table = table.add_columns(cols)
expected = TaggedTable(
{
"feature_1": [0, 1, 2],
"target": [3, 4, 5],
"feature_2": [6, 7, 8],
"feature_3": [9, 6, 3],
},
"target",
None,
)
assert new_table.schema == expected.schema
assert new_table.features == expected.features
assert new_table.target == expected.target
assert new_table == expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from safeds.data.tabular.containers import Row, TaggedTable


def test_should_add_row() -> None:
table = TaggedTable(
{
"feature": [0, 1],
"target": [3, 4],
},
"target",
None,
)
row = Row(
{
"feature": 2,
"target": 5,
},
)
new_table = table.add_row(row)
expected = TaggedTable(
{
"feature": [0, 1, 2],
"target": [3, 4, 5],
},
"target",
None,
)
assert new_table.schema == expected.schema
assert new_table.features == expected.features
assert new_table.target == expected.target
assert new_table == expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from safeds.data.tabular.containers import Row, TaggedTable


def test_should_add_rows() -> None:
table = TaggedTable(
{
"feature": [0, 1],
"target": [4, 5],
},
"target",
None,
)
rows = [
Row(
{
"feature": 2,
"target": 6,
},
),
Row({"feature": 3, "target": 7}),
]
new_table = table.add_rows(rows)
expected = TaggedTable(
{
"feature": [0, 1, 2, 3],
"target": [4, 5, 6, 7],
},
"target",
None,
)
assert new_table.schema == expected.schema
assert new_table.features == expected.features
assert new_table.target == expected.target
assert new_table == expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from safeds.data.tabular.containers import TaggedTable


def test_should_remove_row() -> None:
table = TaggedTable(
{
"feature_1": [3, 9, 6],
"feature_2": [6, 12, 9],
"target": [1, 3, 2],
},
"target",
None,
)
new_table = table.filter_rows(lambda row: all(row.get_value(col) < 10 for col in table.column_names))
expected = TaggedTable(
{
"feature_1": [3, 6],
"feature_2": [6, 9],
"target": [1, 2],
},
"target",
None,
)
assert new_table.schema == expected.schema
assert new_table.features == expected.features
assert new_table.target == expected.target
assert new_table == expected
zzril marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import pytest
from safeds.data.tabular.containers import TaggedTable
from safeds.exceptions import ColumnIsTaggedError


def test_should_remove_column() -> None:
table = TaggedTable(
{
"feature_complete": [0, 1, 2],
"feature_incomplete": [3, None, 5],
"target": [6, 7, 8],
},
"target",
None,
)
new_table = table.remove_columns_with_missing_values()
expected = TaggedTable(
{
"feature_complete": [0, 1, 2],
"target": [6, 7, 8],
},
"target",
None,
)
assert new_table.schema == expected.schema
assert new_table.features == expected.features
assert new_table.target == expected.target
assert new_table == expected


def test_should_throw_column_is_tagged() -> None:
table = TaggedTable(
{
"feature": [0, 1, 2],
"target": [3, None, 5],
},
"target",
None,
)
with pytest.raises(
ColumnIsTaggedError,
match='Illegal schema modification: Column "target" is tagged and cannot be removed.',
):
table.remove_columns_with_missing_values()
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import pytest
from safeds.data.tabular.containers import TaggedTable
from safeds.exceptions import ColumnIsTaggedError


def test_should_remove_column() -> None:
table = TaggedTable(
{
"feature_numerical": [0, 1, 2],
"feature_non_numerical": ["a", "b", "c"],
"target": [3, 4, 5],
},
"target",
None,
)
new_table = table.remove_columns_with_non_numerical_values()
expected = TaggedTable(
{
"feature_numerical": [0, 1, 2],
"target": [3, 4, 5],
},
"target",
None,
)
assert new_table.schema == expected.schema
assert new_table.features == expected.features
assert new_table.target == expected.target
assert new_table == expected


def test_should_throw_column_is_tagged() -> None:
table = TaggedTable(
{
"feature": [0, 1, 2],
"target": ["a", "b", "c"],
},
"target",
None,
)
with pytest.raises(
ColumnIsTaggedError,
match='Illegal schema modification: Column "target" is tagged and cannot be removed.',
):
table.remove_columns_with_non_numerical_values()
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from safeds.data.tabular.containers import TaggedTable


def test_should_remove_row() -> None:
table = TaggedTable(
{
"feature": [0, 0, 1],
"target": [2, 2, 3],
},
"target",
None,
)
new_table = table.remove_duplicate_rows()
expected = TaggedTable(
{
"feature": [0, 1],
"target": [2, 3],
},
"target",
None,
)
assert new_table.schema == expected.schema
assert new_table.features == expected.features
assert new_table.target == expected.target
assert new_table == expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from safeds.data.tabular.containers import TaggedTable


def test_should_remove_row() -> None:
table = TaggedTable(
{
"feature": [0.0, None, 2.0],
"target": [3.0, 4.0, 5.0],
},
"target",
None,
)
new_table = table.remove_rows_with_missing_values()
expected = TaggedTable(
{
"feature": [0.0, 2.0],
"target": [3.0, 5.0],
},
"target",
None,
)
assert new_table.schema == expected.schema
assert new_table.features == expected.features
assert new_table.target == expected.target
assert new_table == expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from safeds.data.tabular.containers import TaggedTable


def test_should_remove_row() -> None:
table = TaggedTable(
{
"feature": [1.0, 11.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0],
"target": [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0],
},
"target",
None,
)
new_table = table.remove_rows_with_outliers()
expected = TaggedTable(
{
"feature": [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0],
"target": [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0],
},
"target",
None,
)
assert new_table.schema == expected.schema
assert new_table.features == expected.features
assert new_table.target == expected.target
assert new_table == expected
Loading