Skip to content

Commit

Permalink
feat: remove list_columns_with_XY methods from Table (#100)
Browse files Browse the repository at this point in the history
Closes #94.

### Summary of Changes

In the `Table` class:
* Remove`list_columns_with_missing_values`
* Remove `list_columns_with_non_numerical_values`
* Mark `list_columns_with_numerical_values` as internal
  • Loading branch information
lars-reimann authored Mar 27, 2023
1 parent de42169 commit a0c56ad
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 66 deletions.
40 changes: 4 additions & 36 deletions src/safeds/data/tabular/containers/_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,7 @@ def drop_columns_with_non_numerical_values(self) -> Table:
A table without the columns that contain non-numerical values.
"""
return Table.from_columns(self.list_columns_with_numerical_values())
return Table.from_columns(self._list_columns_with_numerical_values())

def drop_duplicate_rows(self) -> Table:
"""
Expand Down Expand Up @@ -637,7 +637,7 @@ def drop_rows_with_outliers(self) -> Table:
result = self._data.copy(deep=True)

table_without_nonnumericals = Table.from_columns(
self.list_columns_with_numerical_values()
self._list_columns_with_numerical_values()
)

result = result[
Expand All @@ -662,7 +662,6 @@ def filter_rows(self, query: Callable[[Row], bool]) -> Table:
table : Table
A table containing only the rows filtered by the query.
"""

rows: list[Row] = [row for row in self.to_rows() if query(row)]
if len(rows) == 0:
result_table = Table([], self._schema)
Expand Down Expand Up @@ -936,7 +935,7 @@ def correlation_heatmap(self) -> None:
"""
Plot a correlation heatmap for all numerical columns of this `Table`.
"""
only_numerical = Table.from_columns(self.list_columns_with_numerical_values())
only_numerical = self.drop_columns_with_non_numerical_values()

sns.heatmap(
data=only_numerical._data.corr(),
Expand Down Expand Up @@ -1100,38 +1099,7 @@ def _ipython_display_(self) -> DisplayHandle:
):
return display(tmp)

def list_columns_with_missing_values(self) -> list[Column]:
"""
Return a list of all the columns that have at least one missing value. Returns an empty list if there are none.
Returns
-------
columns_with_missing_values: list[Column]
The list of columns with missing values.
"""
columns = self.to_columns()
columns_with_missing_values = []
for column in columns:
if column.has_missing_values():
columns_with_missing_values.append(column)
return columns_with_missing_values

def list_columns_with_non_numerical_values(self) -> list[Column]:
"""
Return a list of columns only containing non-numerical values.
Returns
-------
cols : list[Column]
The list with only non-numerical columns.
"""
cols = []
for column_name, data_type in self._schema._schema.items():
if not data_type.is_numeric():
cols.append(self.get_column(column_name))
return cols

def list_columns_with_numerical_values(self) -> list[Column]:
def _list_columns_with_numerical_values(self) -> list[Column]:
"""
Return a list of columns only containing numerical values.
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def test_list_columns_with_numerical_values_valid() -> None:
}
)
)
columns = table.list_columns_with_numerical_values()
columns = table._list_columns_with_numerical_values()
assert columns[0] == table.get_column("col3")
assert columns[1] == table.get_column("col4")
assert len(columns) == 2
Expand All @@ -25,6 +25,6 @@ def test_list_columns_with_numerical_values_invalid() -> None:
table = Table(
[], TableSchema({"col1": ColumnType.from_numpy_dtype(np.dtype(float))})
)
columns = table.list_columns_with_numerical_values()
columns = table._list_columns_with_numerical_values()
assert columns[0] == table.get_column("col1")
assert len(columns) == 1

0 comments on commit a0c56ad

Please sign in to comment.