-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes #698 ### Summary of Changes Add a method `Table.remove_rows`. It's the same as `Table.filter_rows` with a negated query.
- Loading branch information
1 parent
f6c379e
commit a1cdaef
Showing
3 changed files
with
93 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
tests/safeds/data/tabular/containers/_table/test_remove_rows.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import pandas as pd | ||
import pytest | ||
from safeds.data.tabular.containers import Table | ||
from safeds.data.tabular.typing import ColumnType, Schema | ||
|
||
|
||
@pytest.mark.parametrize( | ||
("table1", "remove_column", "remove_value", "table2"), | ||
[ | ||
( | ||
Table(), | ||
"col1", | ||
1, | ||
Table._from_pandas_dataframe(pd.DataFrame(), Schema({})), | ||
), | ||
( | ||
Table({"col1": [3, 2, 4], "col2": [1, 2, 4]}), | ||
"col1", | ||
1, | ||
Table({"col1": [3, 2, 4], "col2": [1, 2, 4]}), | ||
), | ||
( | ||
Table({"col1": [1, 2, 1], "col2": [1, 2, 4]}), | ||
"col1", | ||
1, | ||
Table({"col1": [2], "col2": [2]}), | ||
), | ||
], | ||
ids=[ | ||
"empty table", | ||
"no match", | ||
"matches", | ||
], | ||
) | ||
def test_should_remove_rows(table1: Table, remove_column: str, remove_value: ColumnType, table2: Table) -> None: | ||
table1 = table1.remove_rows(lambda row: row.get_value(remove_column) == remove_value) | ||
assert table1.schema == table2.schema | ||
assert table2 == table1 |