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
improvement: drop table column limit, just adjust summary defaults (#2666)
Myles Scolnick41c968eb5d4a
diff --git a/marimo/_plugins/core/json_encoder.py b/marimo/_plugins/core/json_encoder.pyindex 9de44b4fe2..313c05d98b 100644--- a/marimo/_plugins/core/json_encoder.py+++ b/marimo/_plugins/core/json_encoder.py@@ -64,6 +64,10 @@ class WebComponentEncoder(JSONEncoder):if isinstance(o, (dict, list)):return o+ # Handle range+ if isinstance(o, range):+ return list(o)+# Handle MIME objectsif hasattr(o, "_mime_"):mimetype, data = o._mime_()diff --git a/marimo/_plugins/ui/_impl/table.py b/marimo/_plugins/ui/_impl/table.pyindex bddba7be27..b90c9bccd3 100644--- a/marimo/_plugins/ui/_impl/table.py+++ b/marimo/_plugins/ui/_impl/table.py@@ -192,6 +192,7 @@ class table(UIElement[List[str], Union[List[JSONType], IntoDataFrame]]):- `page_size`: the number of rows to show per page.defaults to 10- `show_column_summaries`: whether to show column summaries+ defaults to `True` when the table has less than 40 columns, `False` otherwise- `format_mapping`: a mapping from column names to formatting stringsor functions- `freeze_columns_left`: list of column names to freeze on the left@@ -213,7 +214,7 @@ class table(UIElement[List[str], Union[List[JSONType], IntoDataFrame]]):pagination: Optional[bool] = None,selection: Optional[Literal["single", "multi"]] = "multi",page_size: int = 10,- show_column_summaries: bool = True,+ show_column_summaries: Optional[bool] = None,format_mapping: Optional[Dict[str, Union[str, Callable[..., Any]]]] = None,@@ -243,18 +244,15 @@ class table(UIElement[List[str], Union[List[JSONType], IntoDataFrame]]):self._data = data# Holds the original dataself._manager = get_table_manager(data)- self._show_column_summaries = show_column_summaries- if (- total_cols := self._manager.get_num_columns()- ) > TableManager.DEFAULT_COL_LIMIT:- raise ValueError(- f"Your table has {total_cols} columns, "- "which is greater than the maximum allowed columns of "- f"{TableManager.DEFAULT_COL_LIMIT} for mo.ui.table(). "- "If this is a problem, please open a GitHub issue: "- "https://github.com/marimo-team/marimo/issues"+ # Set the default value for show_column_summaries,+ # if it is not set by the user+ if show_column_summaries is None:+ show_column_summaries = (+ self._manager.get_num_columns()+ <= TableManager.DEFAULT_SUMMARY_CHARTS_COLUMN_LIMIT)+ self._show_column_summaries = show_column_summariesif _internal_column_charts_row_limit is not None:self._column_charts_row_limit = _internal_column_charts_row_limitdiff --git a/marimo/_plugins/ui/_impl/tables/table_manager.py b/marimo/_plugins/ui/_impl/tables/table_manager.pyindex bb0b3151ce..8cf0c4bbaa 100644--- a/marimo/_plugins/ui/_impl/tables/table_manager.py+++ b/marimo/_plugins/ui/_impl/tables/table_manager.py@@ -24,7 +24,10 @@ FieldTypes = Dict[ColumnName, Tuple[FieldType, ExternalDataType]]class TableManager(abc.ABC, Generic[T]):- DEFAULT_COL_LIMIT = 100+ # Upper limit for column summaries+ # The only sets the default to show column summaries,+ # but it can be overridden by the user+ DEFAULT_SUMMARY_CHARTS_COLUMN_LIMIT = 40# Upper limit for frontend table component to show column summary charts# to ensure browser performanceDEFAULT_SUMMARY_CHARTS_ROW_LIMIT = 20_000diff --git a/tests/_plugins/core/test_json_encoder.py b/tests/_plugins/core/test_json_encoder.pyindex dd641d0ca5..d605d9e3af 100644--- a/tests/_plugins/core/test_json_encoder.py+++ b/tests/_plugins/core/test_json_encoder.py@@ -408,3 +408,9 @@ def test_png_encoding() -> None:purple_square = "b'\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00\x14\x00\x00\x00\x14\x08\x02\x00\x00\x00\x02\xeb\x8aZ\x00\x00\x00\tpHYs\x00\x00.#\x00\x00.#\x01x\xa5?v\x00\x00\x00\x1dIDAT8\xcbc\xac\x11\xa9g \x1701P\x00F5\x8fj\x1e\xd5<\xaa\x99r\xcd\x00m\xba\x017\xd3\x00\xdf\xcb\x00\x00\x00\x00IEND\xaeB`\x82'" # noqa: E501encoded = json.dumps(purple_square, cls=WebComponentEncoder)assert isinstance(encoded, str)+++def test_range_encoding() -> None:+ r = range(10)+ encoded = json.dumps(r, cls=WebComponentEncoder)+ assert encoded == "[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]"diff --git a/tests/_plugins/ui/_impl/test_table.py b/tests/_plugins/ui/_impl/test_table.pyindex 639fefeaf3..df4a6cc80e 100644--- a/tests/_plugins/ui/_impl/test_table.py+++ b/tests/_plugins/ui/_impl/test_table.py@@ -294,12 +294,9 @@ def test_value_with_search_then_selection() -> None:assert list(table._convert_value(["2"])) == [{"value": "cherry"}]-def test_table_with_too_many_columns_fails() -> None:+def test_table_with_too_many_columns_passes() -> None:data = {str(i): [1] for i in range(101)}- with pytest.raises(ValueError) as e:- ui.table(data)-- assert "greater than the maximum allowed columns" in str(e)+ assert ui.table(data) is not Nonedef test_table_with_too_many_rows_gets_clamped() -> None:@@ -517,3 +514,45 @@ def test_table_with_filtered_columns_polars() -> None:)assert result.total_rows == 1+++def test_show_column_summaries_default():+ # Test default behavior (True for < 40 columns, False otherwise)+ small_data = {"col" + str(i): range(5) for i in range(39)}+ table_small = ui.table(small_data)+ assert table_small._show_column_summaries is True+ assert table_small._component_args["show-column-summaries"] is True++ large_data = {"col" + str(i): range(5) for i in range(41)}+ table_large = ui.table(large_data)+ assert table_large._show_column_summaries is False+ assert table_large._component_args["show-column-summaries"] is False++ # explicitly set to True+ table_true = ui.table(large_data, show_column_summaries=True)+ assert table_true._show_column_summaries is True+ assert table_true._component_args["show-column-summaries"] is True+++def test_show_column_summaries_explicit():+ # Test explicit setting of show_column_summaries+ data = {"a": [1, 2, 3], "b": [4, 5, 6]}+ table_true = ui.table(data, show_column_summaries=True)+ assert table_true._show_column_summaries is True+ assert table_true._component_args["show-column-summaries"] is True++ table_false = ui.table(data, show_column_summaries=False)+ assert table_false._show_column_summaries is False+ assert table_false._component_args["show-column-summaries"] is False+++def test_show_column_summaries_disabled():+ # Test when show_column_summaries is explicitly set to False+ table = ui.table(+ {"a": [1, 2, 3], "b": [4, 5, 6]}, show_column_summaries=False+ )++ summaries = table.get_column_summaries(EmptyArgs())+ assert summaries.is_disabled is False+ assert summaries.data is None+ assert len(summaries.summaries) == 0