Skip to content

Commit

Permalink
feat: improve error handling of column.stability when given a colum…
Browse files Browse the repository at this point in the history
…n that contains only None (#388)

Closes #319 

### Summary of Changes

The docstring of the method clarifies that the stability is not defined
if a column contains only null values.
The method raises a ValueError if the column contains only null values.

<!-- Please provide a summary of changes in this pull request, ensuring
all changes are explained. -->

---------

Co-authored-by: patrikguempel <128832338+patrikguempel@users.noreply.github.com>
Co-authored-by: Simon Breuer <86068340+sibre28@users.noreply.github.com>
  • Loading branch information
3 people committed Jun 23, 2023
1 parent dbbe0e3 commit 1da2499
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/safeds/data/tabular/containers/_column.py
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ def stability(self) -> float:
\frac{\text{number of occurrences of most common non-null value}}{\text{number of non-null values}}
$$
The stability cannot be calculated for a column with only null values.
The stability is not definded for a column with only null values.
Returns
-------
Expand All @@ -520,7 +520,7 @@ def stability(self) -> float:
raise ColumnSizeError("> 0", "0")

if self.all(lambda x: x is None):
raise ValueError("Stability cannot be calculated for a column with only null values.")
raise ValueError("Stability is not definded for a column with only null values.")

return self._data.value_counts()[self.mode()[0]] / self._data.count()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@ def test_should_raise_column_size_error_if_column_is_empty() -> None:

def test_should_raise_value_error_if_column_contains_only_none() -> None:
column: Column[Any] = Column("A", [None, None])
with pytest.raises(ValueError, match="Stability cannot be calculated for a column with only null values."):
with pytest.raises(ValueError, match="Stability is not definded for a column with only null values."):
column.stability()

0 comments on commit 1da2499

Please sign in to comment.