Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/safeds/data/tabular/containers/_column.py
Original file line number Diff line number Diff line change
Expand Up @@ -1051,10 +1051,12 @@ def stability(self) -> float:
>>> column.stability()
0.5
"""
import polars as pl
non_missing = self._series.drop_nulls()
if non_missing.len() == 0:
return 1.0 # All non-null values are the same (since there is are none)

if type(non_missing.dtype)==pl.datatypes.Boolean:
non_missing = non_missing.cast(str)
mode_count = non_missing.unique_counts().max()
Copy link
Member

@lars-reimann lars-reimann May 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

non_missing.value_counts().get_column("count").max()

Seems to work for boolean as well, which saves us the conversion.


return mode_count / non_missing.len()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,43 @@
},
),
),
(
Table({"col": [True, False, True]}),
Table(
{
"metric": [
"min",
"max",
"mean",
"median",
"standard deviation",
"distinct value count",
"idness",
"missing value ratio",
"stability",
],
"col": [
"-",
"True",
"-",
"-",
"-",
"2",
"0.6666666666666666",
"0.0",
"0.6666666666666666",
],
},
),

)
],
ids=[
"Column of integers and Column of characters",
"empty",
"empty with columns",
"Column of None",
"Column of booleans",
],
)
def test_should_summarize_statistics(table: Table, expected: Table) -> None:
Expand Down