Skip to content

Commit ce15f1d

Browse files
committed
feat: add max_memory_bytes, min_rows_display, and repr_rows parameters to DataFrameHtmlFormatter
1 parent bea52a3 commit ce15f1d

1 file changed

Lines changed: 26 additions & 1 deletion

File tree

python/datafusion/html_formatter.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@ class DataFrameHtmlFormatter:
9191
max_cell_length: Maximum characters to display in a cell before truncation
9292
max_width: Maximum width of the HTML table in pixels
9393
max_height: Maximum height of the HTML table in pixels
94+
max_memory_bytes: Maximum memory in bytes for rendered data (default: 2MB)
95+
min_rows_display: Minimum number of rows to display
96+
repr_rows: Default number of rows to display in repr output
9497
enable_cell_expansion: Whether to add expand/collapse buttons for long cell
9598
values
9699
custom_css: Additional CSS to include in the HTML output
@@ -108,6 +111,9 @@ def __init__(
108111
max_cell_length: int = 25,
109112
max_width: int = 1000,
110113
max_height: int = 300,
114+
max_memory_bytes: int = 2 * 1024 * 1024, # 2 MB
115+
min_rows_display: int = 20,
116+
repr_rows: int = 10,
111117
enable_cell_expansion: bool = True,
112118
custom_css: Optional[str] = None,
113119
show_truncation_message: bool = True,
@@ -124,6 +130,12 @@ def __init__(
124130
Maximum width of the displayed table in pixels.
125131
max_height : int, default 300
126132
Maximum height of the displayed table in pixels.
133+
max_memory_bytes : int, default 2097152 (2MB)
134+
Maximum memory in bytes for rendered data.
135+
min_rows_display : int, default 20
136+
Minimum number of rows to display.
137+
repr_rows : int, default 10
138+
Default number of rows to display in repr output.
127139
enable_cell_expansion : bool, default True
128140
Whether to allow cells to expand when clicked.
129141
custom_css : str, optional
@@ -139,7 +151,8 @@ def __init__(
139151
Raises:
140152
------
141153
ValueError
142-
If max_cell_length, max_width, or max_height is not a positive integer.
154+
If max_cell_length, max_width, max_height, max_memory_bytes,
155+
min_rows_display, or repr_rows is not a positive integer.
143156
TypeError
144157
If enable_cell_expansion, show_truncation_message, or use_shared_styles is
145158
not a boolean,
@@ -158,6 +171,15 @@ def __init__(
158171
if not isinstance(max_height, int) or max_height <= 0:
159172
msg = "max_height must be a positive integer"
160173
raise ValueError(msg)
174+
if not isinstance(max_memory_bytes, int) or max_memory_bytes <= 0:
175+
msg = "max_memory_bytes must be a positive integer"
176+
raise ValueError(msg)
177+
if not isinstance(min_rows_display, int) or min_rows_display <= 0:
178+
msg = "min_rows_display must be a positive integer"
179+
raise ValueError(msg)
180+
if not isinstance(repr_rows, int) or repr_rows <= 0:
181+
msg = "repr_rows must be a positive integer"
182+
raise ValueError(msg)
161183

162184
# Validate boolean parameters
163185
if not isinstance(enable_cell_expansion, bool):
@@ -183,6 +205,9 @@ def __init__(
183205
self.max_cell_length = max_cell_length
184206
self.max_width = max_width
185207
self.max_height = max_height
208+
self.max_memory_bytes = max_memory_bytes
209+
self.min_rows_display = min_rows_display
210+
self.repr_rows = repr_rows
186211
self.enable_cell_expansion = enable_cell_expansion
187212
self.custom_css = custom_css
188213
self.show_truncation_message = show_truncation_message

0 commit comments

Comments
 (0)