Skip to content

Commit 399e3e2

Browse files
committed
Rename min_rows_display to min_rows in formatter configuration and update related tests
1 parent 69bcf6f commit 399e3e2

File tree

4 files changed

+38
-38
lines changed

4 files changed

+38
-38
lines changed

docs/source/user-guide/dataframe/rendering.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ You can customize how DataFrames are rendered by configuring the formatter:
5757
max_width=1000, # Maximum width in pixels
5858
max_height=300, # Maximum height in pixels
5959
max_memory_bytes=2097152, # Maximum memory for rendering (2MB)
60-
min_rows_display=20, # Minimum number of rows to display
60+
min_rows=10, # Minimum number of rows to display
6161
max_rows=10, # Maximum rows to display in __repr__
6262
enable_cell_expansion=True,# Allow expanding truncated cells
6363
custom_css=None, # Additional custom CSS
@@ -190,8 +190,8 @@ You can control how much data is displayed and how much memory is used for rende
190190
191191
configure_formatter(
192192
max_memory_bytes=4 * 1024 * 1024, # 4MB maximum memory for display
193-
min_rows_display=50, # Always show at least 50 rows
194-
max_rows=20 # Show 20 rows in __repr__ output
193+
min_rows=20, # Always show at least 20 rows
194+
max_rows=50 # Show up to 50 rows in output
195195
)
196196
197197
These parameters help balance comprehensive data display against performance considerations.

python/datafusion/dataframe_formatter.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def _validate_formatter_parameters(
6767
max_width: int,
6868
max_height: int,
6969
max_memory_bytes: int,
70-
min_rows_display: int,
70+
min_rows: int,
7171
max_rows: int | None,
7272
repr_rows: int | None,
7373
enable_cell_expansion: bool,
@@ -83,7 +83,7 @@ def _validate_formatter_parameters(
8383
max_width: Maximum width value to validate
8484
max_height: Maximum height value to validate
8585
max_memory_bytes: Maximum memory bytes value to validate
86-
min_rows_display: Minimum rows to display value to validate
86+
min_rows: Minimum rows to display value to validate
8787
max_rows: Maximum rows value to validate (None means use default)
8888
repr_rows: Deprecated repr_rows value to validate
8989
enable_cell_expansion: Boolean expansion flag to validate
@@ -105,7 +105,7 @@ def _validate_formatter_parameters(
105105
_validate_positive_int(max_width, "max_width")
106106
_validate_positive_int(max_height, "max_height")
107107
_validate_positive_int(max_memory_bytes, "max_memory_bytes")
108-
_validate_positive_int(min_rows_display, "min_rows_display")
108+
_validate_positive_int(min_rows, "min_rows")
109109

110110
# Handle deprecated repr_rows parameter
111111
if repr_rows is not None:
@@ -126,9 +126,9 @@ def _validate_formatter_parameters(
126126

127127
_validate_positive_int(max_rows, "max_rows")
128128

129-
# Validate constraint: min_rows_display <= max_rows
130-
if min_rows_display > max_rows:
131-
msg = "min_rows_display must be less than or equal to max_rows"
129+
# Validate constraint: min_rows <= max_rows
130+
if min_rows > max_rows:
131+
msg = "min_rows must be less than or equal to max_rows"
132132
raise ValueError(msg)
133133

134134
# Validate boolean parameters
@@ -214,7 +214,7 @@ class DataFrameHtmlFormatter:
214214
max_width: Maximum width of the HTML table in pixels
215215
max_height: Maximum height of the HTML table in pixels
216216
max_memory_bytes: Maximum memory in bytes for rendered data (default: 2MB)
217-
min_rows_display: Minimum number of rows to display (must be <= max_rows)
217+
min_rows: Minimum number of rows to display (must be <= max_rows)
218218
max_rows: Maximum number of rows to display in repr output
219219
repr_rows: Deprecated alias for max_rows
220220
enable_cell_expansion: Whether to add expand/collapse buttons for long cell
@@ -232,7 +232,7 @@ def __init__(
232232
max_width: int = 1000,
233233
max_height: int = 300,
234234
max_memory_bytes: int = 2 * 1024 * 1024, # 2 MB
235-
min_rows_display: int = 10,
235+
min_rows: int = 10,
236236
max_rows: int | None = None,
237237
repr_rows: int | None = None,
238238
enable_cell_expansion: bool = True,
@@ -253,7 +253,7 @@ def __init__(
253253
Maximum height of the displayed table in pixels.
254254
max_memory_bytes : int, default 2097152 (2MB)
255255
Maximum memory in bytes for rendered data.
256-
min_rows_display : int, default 10
256+
min_rows : int, default 10
257257
Minimum number of rows to display. Must be less than or equal to
258258
``max_rows``.
259259
max_rows : int, default 10
@@ -276,7 +276,7 @@ def __init__(
276276
------
277277
ValueError
278278
If max_cell_length, max_width, max_height, max_memory_bytes,
279-
min_rows_display or max_rows is not a positive integer.
279+
min_rows or max_rows is not a positive integer.
280280
TypeError
281281
If enable_cell_expansion, show_truncation_message, or use_shared_styles is
282282
not a boolean,
@@ -290,7 +290,7 @@ def __init__(
290290
max_width,
291291
max_height,
292292
max_memory_bytes,
293-
min_rows_display,
293+
min_rows,
294294
max_rows,
295295
repr_rows,
296296
enable_cell_expansion,
@@ -304,7 +304,7 @@ def __init__(
304304
self.max_width = max_width
305305
self.max_height = max_height
306306
self.max_memory_bytes = max_memory_bytes
307-
self.min_rows_display = min_rows_display
307+
self.min_rows = min_rows
308308
self._max_rows = resolved_max_rows
309309
self.enable_cell_expansion = enable_cell_expansion
310310
self.custom_css = custom_css
@@ -794,7 +794,7 @@ def configure_formatter(**kwargs: Any) -> None:
794794
"max_width",
795795
"max_height",
796796
"max_memory_bytes",
797-
"min_rows_display",
797+
"min_rows",
798798
"max_rows",
799799
"repr_rows",
800800
"enable_cell_expansion",

python/tests/test_dataframe.py

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1438,7 +1438,7 @@ def get_header_style(self) -> str:
14381438

14391439
def test_html_formatter_memory(df, clean_formatter_state):
14401440
"""Test the memory and row control parameters in DataFrameHtmlFormatter."""
1441-
configure_formatter(max_memory_bytes=10, min_rows_display=1)
1441+
configure_formatter(max_memory_bytes=10, min_rows=1)
14421442
html_output = df._repr_html_()
14431443

14441444
# Count the number of table rows in the output
@@ -1448,7 +1448,7 @@ def test_html_formatter_memory(df, clean_formatter_state):
14481448
assert tr_count == 2 # 1 for header row, 1 for data row
14491449
assert "data truncated" in html_output.lower()
14501450

1451-
configure_formatter(max_memory_bytes=10 * MB, min_rows_display=1)
1451+
configure_formatter(max_memory_bytes=10 * MB, min_rows=1)
14521452
html_output = df._repr_html_()
14531453
# With larger memory limit and min_rows=2, should display all rows
14541454
tr_count = count_table_rows(html_output)
@@ -1468,55 +1468,55 @@ def test_html_formatter_memory_boundary_conditions(df, clean_formatter_state):
14681468

14691469
# Get the raw size of the data to test boundary conditions
14701470
# First, capture output with no limits
1471-
configure_formatter(max_memory_bytes=10 * MB, min_rows_display=1, max_rows=100)
1471+
configure_formatter(max_memory_bytes=10 * MB, min_rows=1, max_rows=100)
14721472
unrestricted_output = df._repr_html_()
14731473
unrestricted_rows = count_table_rows(unrestricted_output)
14741474

14751475
# Test 1: Very small memory limit should still respect min_rows
1476-
configure_formatter(max_memory_bytes=10, min_rows_display=1)
1476+
configure_formatter(max_memory_bytes=10, min_rows=1)
14771477
html_output = df._repr_html_()
14781478
tr_count = count_table_rows(html_output)
14791479
assert tr_count >= 2 # At least header + 1 data row (minimum)
14801480
# Should show truncation since we limited memory so aggressively
14811481
assert "data truncated" in html_output.lower()
14821482

14831483
# Test 2: Memory limit at default size should work well
1484-
configure_formatter(max_memory_bytes=2 * MB, min_rows_display=1)
1484+
configure_formatter(max_memory_bytes=2 * MB, min_rows=1)
14851485
html_output = df._repr_html_()
14861486
tr_count = count_table_rows(html_output)
14871487
assert tr_count >= 2 # At least header + min_rows
14881488

14891489
# Test 3: Very large memory limit should show all data
1490-
configure_formatter(max_memory_bytes=100 * MB, min_rows_display=1)
1490+
configure_formatter(max_memory_bytes=100 * MB, min_rows=1)
14911491
html_output = df._repr_html_()
14921492
tr_count = count_table_rows(html_output)
14931493
assert tr_count == unrestricted_rows # Should show all rows
14941494

14951495
# Test 4: Min rows should override memory limit
14961496
# With tiny memory and larger min_rows, min_rows should win
1497-
configure_formatter(max_memory_bytes=10, min_rows_display=2)
1497+
configure_formatter(max_memory_bytes=10, min_rows=2)
14981498
html_output = df._repr_html_()
14991499
tr_count = count_table_rows(html_output)
15001500
assert tr_count >= 3 # At least header + 2 data rows (min_rows)
15011501
# Should show truncation message despite min_rows being satisfied
15021502
assert "data truncated" in html_output.lower()
15031503

15041504
# Test 5: Default memory limit with different min_rows
1505-
configure_formatter(max_memory_bytes=2 * MB, min_rows_display=2, max_rows=2)
1505+
configure_formatter(max_memory_bytes=2 * MB, min_rows=2, max_rows=2)
15061506
html_output = df._repr_html_()
15071507
tr_count = count_table_rows(html_output)
15081508
assert tr_count == 3 # header + 2 data rows
15091509

15101510

15111511
def test_html_formatter_max_rows(df, clean_formatter_state):
1512-
configure_formatter(min_rows_display=2, max_rows=2)
1512+
configure_formatter(min_rows=2, max_rows=2)
15131513
html_output = df._repr_html_()
15141514

15151515
tr_count = count_table_rows(html_output)
15161516
# Table should have header row (1) + 2 data rows = 3 rows
15171517
assert tr_count == 3
15181518

1519-
configure_formatter(min_rows_display=2, max_rows=3)
1519+
configure_formatter(min_rows=2, max_rows=3)
15201520
html_output = df._repr_html_()
15211521

15221522
tr_count = count_table_rows(html_output)
@@ -1542,11 +1542,11 @@ def test_html_formatter_validation():
15421542
with pytest.raises(ValueError, match="max_memory_bytes must be a positive integer"):
15431543
DataFrameHtmlFormatter(max_memory_bytes=-100)
15441544

1545-
with pytest.raises(ValueError, match="min_rows_display must be a positive integer"):
1546-
DataFrameHtmlFormatter(min_rows_display=0)
1545+
with pytest.raises(ValueError, match="min_rows must be a positive integer"):
1546+
DataFrameHtmlFormatter(min_rows=0)
15471547

1548-
with pytest.raises(ValueError, match="min_rows_display must be a positive integer"):
1549-
DataFrameHtmlFormatter(min_rows_display=-5)
1548+
with pytest.raises(ValueError, match="min_rows must be a positive integer"):
1549+
DataFrameHtmlFormatter(min_rows=-5)
15501550

15511551
with pytest.raises(ValueError, match="max_rows must be a positive integer"):
15521552
DataFrameHtmlFormatter(max_rows=0)
@@ -1555,16 +1555,16 @@ def test_html_formatter_validation():
15551555
DataFrameHtmlFormatter(max_rows=-10)
15561556

15571557
with pytest.raises(
1558-
ValueError, match="min_rows_display must be less than or equal to max_rows"
1558+
ValueError, match="min_rows must be less than or equal to max_rows"
15591559
):
1560-
DataFrameHtmlFormatter(min_rows_display=5, max_rows=4)
1560+
DataFrameHtmlFormatter(min_rows=5, max_rows=4)
15611561

15621562

15631563
def test_repr_rows_backward_compatibility(clean_formatter_state):
15641564
"""Test that repr_rows parameter still works as deprecated alias."""
15651565
# Should work when not conflicting with max_rows
15661566
with pytest.warns(DeprecationWarning, match="repr_rows parameter is deprecated"):
1567-
formatter = DataFrameHtmlFormatter(repr_rows=15, min_rows_display=10)
1567+
formatter = DataFrameHtmlFormatter(repr_rows=15, min_rows=10)
15681568
assert formatter.max_rows == 15
15691569
assert formatter.repr_rows == 15
15701570

@@ -1589,7 +1589,7 @@ def test_configure_formatter(df, clean_formatter_state):
15891589
max_width = 500
15901590
max_height = 30
15911591
max_memory_bytes = 3 * MB
1592-
min_rows_display = 2
1592+
min_rows = 2
15931593
max_rows = 2
15941594
enable_cell_expansion = False
15951595
show_truncation_message = False
@@ -1602,7 +1602,7 @@ def test_configure_formatter(df, clean_formatter_state):
16021602
assert formatter_default.max_width != max_width
16031603
assert formatter_default.max_height != max_height
16041604
assert formatter_default.max_memory_bytes != max_memory_bytes
1605-
assert formatter_default.min_rows_display != min_rows_display
1605+
assert formatter_default.min_rows != min_rows
16061606
assert formatter_default.max_rows != max_rows
16071607
assert formatter_default.enable_cell_expansion != enable_cell_expansion
16081608
assert formatter_default.show_truncation_message != show_truncation_message
@@ -1614,7 +1614,7 @@ def test_configure_formatter(df, clean_formatter_state):
16141614
max_width=max_width,
16151615
max_height=max_height,
16161616
max_memory_bytes=max_memory_bytes,
1617-
min_rows_display=min_rows_display,
1617+
min_rows=min_rows,
16181618
max_rows=max_rows,
16191619
enable_cell_expansion=enable_cell_expansion,
16201620
show_truncation_message=show_truncation_message,
@@ -1625,7 +1625,7 @@ def test_configure_formatter(df, clean_formatter_state):
16251625
assert formatter_custom.max_width == max_width
16261626
assert formatter_custom.max_height == max_height
16271627
assert formatter_custom.max_memory_bytes == max_memory_bytes
1628-
assert formatter_custom.min_rows_display == min_rows_display
1628+
assert formatter_custom.min_rows == min_rows
16291629
assert formatter_custom.max_rows == max_rows
16301630
assert formatter_custom.enable_cell_expansion == enable_cell_expansion
16311631
assert formatter_custom.show_truncation_message == show_truncation_message

src/dataframe.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ where
152152
fn build_formatter_config_from_python(formatter: &Bound<'_, PyAny>) -> PyResult<FormatterConfig> {
153153
let default_config = FormatterConfig::default();
154154
let max_bytes = get_attr(formatter, "max_memory_bytes", default_config.max_bytes);
155-
let min_rows = get_attr(formatter, "min_rows_display", default_config.min_rows);
155+
let min_rows = get_attr(formatter, "min_rows", default_config.min_rows);
156156
let max_rows = get_attr(formatter, "max_rows", default_config.max_rows);
157157

158158
let config = FormatterConfig {

0 commit comments

Comments
 (0)