A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.
Python artificial-intelligencedagdata-sciencedata-visualizationdataflowdeveloper-toolsmachine-learningnotebookspipelinepythonreactivesqlweb-app
fix: boolean column stats counted nulls as False, displaying incorrect totals (#10866)
Nick Greenfieldfe5d9e65b39c
diff --git a/frontend/src/components/data-table/column-summary/chart-spec-model.tsx b/frontend/src/components/data-table/column-summary/chart-spec-model.tsxindex 1819347310..b590dad59d 100644--- a/frontend/src/components/data-table/column-summary/chart-spec-model.tsx+++ b/frontend/src/components/data-table/column-summary/chart-spec-model.tsx@@ -573,7 +573,7 @@ export class ColumnChartSpecModel<T> {};}case "boolean": {- if (!stats?.true || !stats?.false) {+ if (stats?.true == null || stats?.false == null) {return getLegacyBooleanSpec(column, base, MAX_BAR_HEIGHT);}diff --git a/marimo/_plugins/ui/_impl/tables/narwhals_table.py b/marimo/_plugins/ui/_impl/tables/narwhals_table.pyindex b88fc1cb21..839ad9210c 100644--- a/marimo/_plugins/ui/_impl/tables/narwhals_table.py+++ b/marimo/_plugins/ui/_impl/tables/narwhals_table.py@@ -441,7 +441,8 @@ class NarwhalsTableManager(exprs.update({"true": col.sum(), # type: ignore[dict-item]- "false": nw.len() - col.sum(), # type: ignore[dict-item]+ # nulls are neither true nor false+ "false": nw.len() - col.sum() - col.null_count(), # type: ignore[dict-item]})elif (dtype == nw.Date) or is_narwhals_time_type(dtype):diff --git a/tests/_plugins/ui/_impl/tables/test_narwhals.py b/tests/_plugins/ui/_impl/tables/test_narwhals.pyindex 53a3c222a4..195dc3161c 100644--- a/tests/_plugins/ui/_impl/tables/test_narwhals.py+++ b/tests/_plugins/ui/_impl/tables/test_narwhals.py@@ -491,6 +491,18 @@ class TestNarwhalsTableManagerFactory(unittest.TestCase):assert isinstance(bool_stats.true, int)assert isinstance(bool_stats.false, int)+ def test_bool_stats_exclude_nulls(self) -> None:+ import polars as pl++ data = pl.DataFrame({"b": [True, False, None, True, None]})+ manager = NarwhalsTableManager.from_dataframe(data)+ assert manager.get_stats("b") == ColumnStats(+ total=5,+ nulls=2,+ true=2,+ false=1,+ )+def test_summary_all_nan_column_no_warning(self) -> None:import warnings