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
improve: hide column summaries for very small tables (#4177)
Akshay Agrawal0c755d6db0fe
diff --git a/marimo/_plugins/ui/_impl/table.py b/marimo/_plugins/ui/_impl/table.pyindex c1707c98ac..8bbacb6415 100644--- a/marimo/_plugins/ui/_impl/table.py+++ b/marimo/_plugins/ui/_impl/table.py@@ -212,7 +212,7 @@ class table(initial_selection (Union[List[int], List[tuple[str, str]), optional): Indices of the rows you want selected by default.page_size (int, optional): The number of rows to show per page. Defaults to 10.show_column_summaries (Union[bool, Literal["stats", "chart"]], optional): Whether to show column summaries.- Defaults to True when the table has less than 40 columns, False otherwise.+ Defaults to True when the table has less than 40 columns and at least 10 rows, False otherwise.If "stats", only show stats. If "chart", only show charts.show_download (bool, optional): Whether to show the download button.Defaults to True for dataframes, False otherwise.@@ -297,12 +297,26 @@ class table(self._manager = get_table_manager(data)self._max_columns = max_columns+ if _internal_total_rows is not None:+ total_rows = _internal_total_rows+ else:+ num_rows = self._manager.get_num_rows(force=True)+ total_rows = num_rows if num_rows is not None else "too_many"+# Set the default value for show_column_summaries,# if it is not set by the userif show_column_summaries is None:- show_column_summaries = (- self._manager.get_num_columns()- <= TableManager.DEFAULT_SUMMARY_CHARTS_COLUMN_LIMIT+ # cast to bool --- comparison come back as a NumPy bool+ show_column_summaries = bool(+ (+ self._manager.get_num_columns()+ <= TableManager.DEFAULT_SUMMARY_CHARTS_COLUMN_LIMIT+ )+ and (+ total_rows == "too_many"+ or total_rows+ >= TableManager.DEFAULT_SUMMARY_CHARTS_MINIMUM_ROWS+ ))self._show_column_summaries = show_column_summaries@@ -391,12 +405,6 @@ class table(field_types = self._manager.get_field_types()- if _internal_total_rows is not None:- total_rows = _internal_total_rows- else:- num_rows = self._manager.get_num_rows(force=True)- total_rows = num_rows if num_rows is not None else "too_many"-if pagination is False and total_rows != "too_many":page_size = total_rows# pagination defaults to True if there are more than page_size rowsdiff --git a/marimo/_plugins/ui/_impl/tables/table_manager.py b/marimo/_plugins/ui/_impl/tables/table_manager.pyindex 231516c6dc..9b8b96cad1 100644--- a/marimo/_plugins/ui/_impl/tables/table_manager.py+++ b/marimo/_plugins/ui/_impl/tables/table_manager.py@@ -43,6 +43,9 @@ class TableManager(abc.ABC, Generic[T]):# Upper limit for frontend table component to show column summary charts# to ensure browser performanceDEFAULT_SUMMARY_CHARTS_ROW_LIMIT = 20_000+ # Lower limit for frontend to show column summary charts, since for+ # very small tables column summaries just take up space.+ DEFAULT_SUMMARY_CHARTS_MINIMUM_ROWS = 11# Upper limit for column summaries to avoid hanging up the kernel# Note: Keep this value in sync with DataTablePlugin's banner textDEFAULT_SUMMARY_STATS_ROW_LIMIT = 1_000_000