-
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.
### Summary of Changes * New method `Table.keep_only_rows`. This is consistent with `Table.keep_only_columns`. * Deprecate `Table.filter_rows`, which does the same thing. It will be removed in a future version.
- Loading branch information
1 parent
a1cdaef
commit 923a6c2
Showing
3 changed files
with
90 additions
and
13 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
38 changes: 38 additions & 0 deletions
38
tests/safeds/data/tabular/containers/_table/test_keep_only_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, Integer, Schema | ||
|
||
|
||
@pytest.mark.parametrize( | ||
("table1", "filter_column", "filter_value", "table2"), | ||
[ | ||
( | ||
Table(), | ||
"col1", | ||
1, | ||
Table._from_pandas_dataframe(pd.DataFrame(), Schema({})), | ||
), | ||
( | ||
Table({"col1": [3, 2, 4], "col2": [1, 2, 4]}), | ||
"col1", | ||
1, | ||
Table._from_pandas_dataframe(pd.DataFrame(), Schema({"col1": Integer(), "col2": Integer()})), | ||
), | ||
( | ||
Table({"col1": [1, 2, 1], "col2": [1, 2, 4]}), | ||
"col1", | ||
1, | ||
Table({"col1": [1, 1], "col2": [1, 4]}), | ||
), | ||
], | ||
ids=[ | ||
"empty table", | ||
"no matches", | ||
"matches", | ||
], | ||
) | ||
def test_should_keep_only_rows(table1: Table, filter_column: str, filter_value: ColumnType, table2: Table) -> None: | ||
table1 = table1.keep_only_rows(lambda row: row.get_value(filter_column) == filter_value) | ||
assert table1.schema == table2.schema | ||
assert table2 == table1 |
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