Skip to content

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.

fix: raise valueError for pageSize > 200 (#3472)

Shahmir Varqha7641d41e4ad3
diff --git a/marimo/_plugins/ui/_impl/data_editor.py b/marimo/_plugins/ui/_impl/data_editor.py
index e2ffe62945..eca1ed2b43 100644
--- a/marimo/_plugins/ui/_impl/data_editor.py
+++ b/marimo/_plugins/ui/_impl/data_editor.py
@@ -25,6 +25,7 @@ from marimo import _loggers
from marimo._output.rich_help import mddoc
from marimo._plugins.ui._core.ui_element import UIElement
from marimo._plugins.ui._impl.tables.utils import get_table_manager
+from marimo._plugins.validators import validate_page_size
LOGGER = _loggers.marimo_logger()
@@ -142,6 +143,7 @@ class data_editor(
]
] = None,
) -> None:
+ validate_page_size(page_size)
table_manager = get_table_manager(data)
size = table_manager.get_num_rows()
diff --git a/marimo/_plugins/ui/_impl/dataframes/dataframe.py b/marimo/_plugins/ui/_impl/dataframes/dataframe.py
index c346ec6704..b39dba96f7 100644
--- a/marimo/_plugins/ui/_impl/dataframes/dataframe.py
+++ b/marimo/_plugins/ui/_impl/dataframes/dataframe.py
@@ -36,7 +36,10 @@ from marimo._plugins.ui._impl.tables.table_manager import (
from marimo._plugins.ui._impl.tables.utils import (
get_table_manager,
)
-from marimo._plugins.validators import validate_no_integer_columns
+from marimo._plugins.validators import (
+ validate_no_integer_columns,
+ validate_page_size,
+)
from marimo._runtime.functions import EmptyArgs, Function
from marimo._utils.memoize import memoize_last_value
from marimo._utils.parse_dataclass import parse_raw
@@ -141,6 +144,7 @@ class dataframe(UIElement[Dict[str, Any], DataFrameType]):
self._error: Optional[str] = None
self._last_transforms = Transformations([])
self._page_size = page_size or 5 # Default to 5 rows (.head())
+ validate_page_size(self._page_size)
super().__init__(
component_name=dataframe._name,
diff --git a/marimo/_plugins/ui/_impl/table.py b/marimo/_plugins/ui/_impl/table.py
index 0df9236ab9..d62837ff92 100644
--- a/marimo/_plugins/ui/_impl/table.py
+++ b/marimo/_plugins/ui/_impl/table.py
@@ -38,7 +38,10 @@ from marimo._plugins.ui._impl.tables.table_manager import (
)
from marimo._plugins.ui._impl.tables.utils import get_table_manager
from marimo._plugins.ui._impl.utils.dataframe import ListOrTuple, TableData
-from marimo._plugins.validators import validate_no_integer_columns
+from marimo._plugins.validators import (
+ validate_no_integer_columns,
+ validate_page_size,
+)
from marimo._runtime.functions import EmptyArgs, Function
from marimo._utils.narwhals_utils import unwrap_narwhals_dataframe
@@ -254,6 +257,7 @@ class table(UIElement[List[str], Union[List[JSONType], IntoDataFrame]]):
_internal_total_rows: Optional[Union[int, Literal["too_many"]]] = None,
) -> None:
validate_no_integer_columns(data)
+ validate_page_size(page_size)
# The original data passed in
self._data = data
diff --git a/marimo/_plugins/validators.py b/marimo/_plugins/validators.py
index 935d24b63e..83d3b5faa9 100644
--- a/marimo/_plugins/validators.py
+++ b/marimo/_plugins/validators.py
@@ -77,3 +77,11 @@ def validate_no_integer_columns(df: Any) -> None:
"Please use strings for column names.",
stacklevel=3,
)
+
+
+# issue: https://github.com/marimo-team/marimo/issues/3407
+def validate_page_size(page_size: int) -> None:
+ if page_size > 200:
+ raise ValueError(
+ "Page size limited to 200 rows. If you'd like this increased, please file an issue"
+ )
diff --git a/tests/_plugins/ui/_impl/dataframes/test_dataframe.py b/tests/_plugins/ui/_impl/dataframes/test_dataframe.py
index 353120dea8..6f746b4ef0 100644
--- a/tests/_plugins/ui/_impl/dataframes/test_dataframe.py
+++ b/tests/_plugins/ui/_impl/dataframes/test_dataframe.py
@@ -217,6 +217,13 @@ class TestDataframes:
assert search_result.total_rows == 100
assert search_result.data == result.url
+ @staticmethod
+ def test_dataframe_too_large_page_size() -> None:
+ df = pd.DataFrame({"A": range(300)})
+ with pytest.raises(ValueError) as e:
+ _ = ui.dataframe(df, page_size=201)
+ assert "limited to 200 rows" in str(e.value)
+
@staticmethod
def test_dataframe_with_non_string_column_names() -> None:
df = pd.DataFrame(
diff --git a/tests/_plugins/ui/_impl/test_data_editor.py b/tests/_plugins/ui/_impl/test_data_editor.py
index c502891404..f5416ae586 100644
--- a/tests/_plugins/ui/_impl/test_data_editor.py
+++ b/tests/_plugins/ui/_impl/test_data_editor.py
@@ -394,6 +394,15 @@ def test_data_editor_with_custom_pagination():
assert editor._component_args["page-size"] == 25
+ not DependencyManager.polars.has(), reason="Polars not installed"
+)
+def test_data_editor_with_too_large_pagesize():
+ data = [{"A": i} for i in range(300)]
+ with pytest.raises(ValueError):
+ _ = data_editor(data=data, page_size=201)
+
+
@pytest.mark.skipif(
not DependencyManager.polars.has(), reason="Polars not installed"
)
diff --git a/tests/_plugins/ui/_impl/test_table.py b/tests/_plugins/ui/_impl/test_table.py
index e39673c454..ae56430497 100644
--- a/tests/_plugins/ui/_impl/test_table.py
+++ b/tests/_plugins/ui/_impl/test_table.py
@@ -396,6 +396,13 @@ def test_table_with_too_many_rows_gets_clamped() -> None:
assert len(table._component_args["data"]) == 10
+def test_table_too_large_pagesize_throws_error() -> None:
+ data = {"a": list(range(20_002))}
+ with pytest.raises(ValueError) as e:
+ _ = ui.table(data, page_size=201)
+ assert "limited to 200 rows" in str(e.value)
+
+
def test_can_get_second_page() -> None:
data = {"a": list(range(40))}
table = ui.table(data)