-
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.
feat: function to drop columns/rows with missing values (#97)
Closes #10. ### Summary of Changes Add methods to `Table` to handle missing values: * `drop_columns_with_missing_values` returns a `Table` without the columns that have missing values. * `drop_rows_with_missing_values` returns a `Table` without the rows that have missing values. --------- Co-authored-by: lars-reimann <[email protected]>
- Loading branch information
1 parent
8f14d65
commit 05d771c
Showing
3 changed files
with
82 additions
and
2 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
27 changes: 27 additions & 0 deletions
27
tests/safeds/data/tabular/containers/_table/test_drop_columns_with_missing_values.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,27 @@ | ||
import numpy as np | ||
import pandas as pd | ||
from safeds.data.tabular.containers import Table | ||
from safeds.data.tabular.typing import ColumnType, TableSchema | ||
|
||
|
||
def test_drop_columns_with_missing_values_valid() -> None: | ||
table = Table( | ||
pd.DataFrame( | ||
data={ | ||
"col1": [None, None, None, None], | ||
"col2": [1, 2, 3, None], | ||
"col3": [1, 2, 3, 4], | ||
"col4": [2, 3, 1, 4], | ||
} | ||
) | ||
) | ||
updated_table = table.drop_columns_with_missing_values() | ||
assert updated_table.get_column_names() == ["col3", "col4"] | ||
|
||
|
||
def test_drop_columns_with_missing_values_empty() -> None: | ||
table = Table( | ||
[], TableSchema({"col1": ColumnType.from_numpy_dtype(np.dtype(float))}) | ||
) | ||
updated_table = table.drop_columns_with_missing_values() | ||
assert updated_table.get_column_names() == ["col1"] |
27 changes: 27 additions & 0 deletions
27
tests/safeds/data/tabular/containers/_table/test_drop_rows_with_missing_values.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,27 @@ | ||
import numpy as np | ||
import pandas as pd | ||
from safeds.data.tabular.containers import Table | ||
from safeds.data.tabular.typing import ColumnType, TableSchema | ||
|
||
|
||
def test_drop_rows_with_missing_values_valid() -> None: | ||
table = Table( | ||
pd.DataFrame( | ||
data={ | ||
"col1": [None, None, "C", "A"], | ||
"col2": [None, "Test1", "Test3", "Test1"], | ||
"col3": [None, 2, 3, 4], | ||
"col4": [None, 3, 1, 4], | ||
} | ||
) | ||
) | ||
updated_table = table.drop_rows_with_missing_values() | ||
assert updated_table.count_rows() == 2 | ||
|
||
|
||
def test_drop_rows_with_missing_values_empty() -> None: | ||
table = Table( | ||
[], TableSchema({"col1": ColumnType.from_numpy_dtype(np.dtype(float))}) | ||
) | ||
updated_table = table.drop_rows_with_missing_values() | ||
assert updated_table.get_column_names() == ["col1"] |