From fe745e4f9d3c30c66f0417ce98b86458e027616b Mon Sep 17 00:00:00 2001 From: Saman Hushi Date: Fri, 17 May 2024 10:02:52 +0200 Subject: [PATCH 1/3] cast bool to str when stability is called to prevent error from unique_counts --- src/safeds/data/tabular/containers/_column.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/safeds/data/tabular/containers/_column.py b/src/safeds/data/tabular/containers/_column.py index 3dc1781e1..4152f2125 100644 --- a/src/safeds/data/tabular/containers/_column.py +++ b/src/safeds/data/tabular/containers/_column.py @@ -1051,10 +1051,13 @@ 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) + print(non_missing) mode_count = non_missing.unique_counts().max() return mode_count / non_missing.len() From d8330c1e1e54909a9adba38ba0686a85637cd403 Mon Sep 17 00:00:00 2001 From: Saman Hushi Date: Fri, 17 May 2024 10:04:15 +0200 Subject: [PATCH 2/3] removed debug print --- src/safeds/data/tabular/containers/_column.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/safeds/data/tabular/containers/_column.py b/src/safeds/data/tabular/containers/_column.py index 4152f2125..6ca992810 100644 --- a/src/safeds/data/tabular/containers/_column.py +++ b/src/safeds/data/tabular/containers/_column.py @@ -1057,7 +1057,6 @@ def stability(self) -> float: 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) - print(non_missing) mode_count = non_missing.unique_counts().max() return mode_count / non_missing.len() From ae0eb4c18296f2cd82f9387720884d42a45536d7 Mon Sep 17 00:00:00 2001 From: Saman Hushi Date: Fri, 17 May 2024 10:34:27 +0200 Subject: [PATCH 3/3] added test for bool col --- .../_table/test_summarize_statistics.py | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/tests/safeds/data/tabular/containers/_table/test_summarize_statistics.py b/tests/safeds/data/tabular/containers/_table/test_summarize_statistics.py index 0b3fe5c66..920f519d0 100644 --- a/tests/safeds/data/tabular/containers/_table/test_summarize_statistics.py +++ b/tests/safeds/data/tabular/containers/_table/test_summarize_statistics.py @@ -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: