Skip to content

Commit ec3d786

Browse files
jorisvandenbosscheTomAugspurger
authored andcommitted
DataFrame html repr: also follow min_rows setting (#27991)
* DataFrame html repr: also follow min_rows setting * add whatsnew
1 parent d2031d7 commit ec3d786

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

doc/source/whatsnew/v0.25.1.rst

+1
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ I/O
105105
^^^
106106
- Avoid calling ``S3File.s3`` when reading parquet, as this was removed in s3fs version 0.3.0 (:issue:`27756`)
107107
- Better error message when a negative header is passed in :func:`pandas.read_csv` (:issue:`27779`)
108+
- Follow the ``min_rows`` display option (introduced in v0.25.0) correctly in the html repr in the notebook (:issue:`27991`).
108109
-
109110

110111
Plotting

pandas/core/frame.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -670,15 +670,18 @@ def _repr_html_(self):
670670

671671
if get_option("display.notebook_repr_html"):
672672
max_rows = get_option("display.max_rows")
673+
min_rows = get_option("display.min_rows")
673674
max_cols = get_option("display.max_columns")
674675
show_dimensions = get_option("display.show_dimensions")
675676

676-
return self.to_html(
677+
formatter = fmt.DataFrameFormatter(
678+
self,
677679
max_rows=max_rows,
680+
min_rows=min_rows,
678681
max_cols=max_cols,
679682
show_dimensions=show_dimensions,
680-
notebook=True,
681683
)
684+
return formatter.to_html(notebook=True)
682685
else:
683686
return None
684687

pandas/tests/io/formats/test_format.py

+7
Original file line numberDiff line numberDiff line change
@@ -471,28 +471,35 @@ def test_repr_min_rows(self):
471471

472472
# default setting no truncation even if above min_rows
473473
assert ".." not in repr(df)
474+
assert ".." not in df._repr_html_()
474475

475476
df = pd.DataFrame({"a": range(61)})
476477

477478
# default of max_rows 60 triggers truncation if above
478479
assert ".." in repr(df)
480+
assert ".." in df._repr_html_()
479481

480482
with option_context("display.max_rows", 10, "display.min_rows", 4):
481483
# truncated after first two rows
482484
assert ".." in repr(df)
483485
assert "2 " not in repr(df)
486+
assert "..." in df._repr_html_()
487+
assert "<td>2</td>" not in df._repr_html_()
484488

485489
with option_context("display.max_rows", 12, "display.min_rows", None):
486490
# when set to None, follow value of max_rows
487491
assert "5 5" in repr(df)
492+
assert "<td>5</td>" in df._repr_html_()
488493

489494
with option_context("display.max_rows", 10, "display.min_rows", 12):
490495
# when set value higher as max_rows, use the minimum
491496
assert "5 5" not in repr(df)
497+
assert "<td>5</td>" not in df._repr_html_()
492498

493499
with option_context("display.max_rows", None, "display.min_rows", 12):
494500
# max_rows of None -> never truncate
495501
assert ".." not in repr(df)
502+
assert ".." not in df._repr_html_()
496503

497504
def test_str_max_colwidth(self):
498505
# GH 7856

0 commit comments

Comments
 (0)