Skip to content

Commit 8795cb7

Browse files
meeseeksmachinejorisvandenbossche
authored andcommitted
Backport PR pandas-dev#27991 on branch 0.25.x (DataFrame html repr: also follow min_rows setting) (pandas-dev#28044)
* Backport PR pandas-dev#27991: DataFrame html repr: also follow min_rows setting * fix return value
1 parent b9bea59 commit 8795cb7

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

doc/source/whatsnew/v0.25.1.rst

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

111112
Plotting

pandas/core/frame.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -673,15 +673,19 @@ def _repr_html_(self):
673673

674674
if get_option("display.notebook_repr_html"):
675675
max_rows = get_option("display.max_rows")
676+
min_rows = get_option("display.min_rows")
676677
max_cols = get_option("display.max_columns")
677678
show_dimensions = get_option("display.show_dimensions")
678679

679-
return self.to_html(
680+
formatter = fmt.DataFrameFormatter(
681+
self,
680682
max_rows=max_rows,
683+
min_rows=min_rows,
681684
max_cols=max_cols,
682685
show_dimensions=show_dimensions,
683-
notebook=True,
684686
)
687+
formatter.to_html(notebook=True)
688+
return formatter.buf.getvalue()
685689
else:
686690
return None
687691

pandas/tests/io/formats/test_format.py

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

423423
# default setting no truncation even if above min_rows
424424
assert ".." not in repr(df)
425+
assert ".." not in df._repr_html_()
425426

426427
df = pd.DataFrame({"a": range(61)})
427428

428429
# default of max_rows 60 triggers truncation if above
429430
assert ".." in repr(df)
431+
assert ".." in df._repr_html_()
430432

431433
with option_context("display.max_rows", 10, "display.min_rows", 4):
432434
# truncated after first two rows
433435
assert ".." in repr(df)
434436
assert "2 " not in repr(df)
437+
assert "..." in df._repr_html_()
438+
assert "<td>2</td>" not in df._repr_html_()
435439

436440
with option_context("display.max_rows", 12, "display.min_rows", None):
437441
# when set to None, follow value of max_rows
438442
assert "5 5" in repr(df)
443+
assert "<td>5</td>" in df._repr_html_()
439444

440445
with option_context("display.max_rows", 10, "display.min_rows", 12):
441446
# when set value higher as max_rows, use the minimum
442447
assert "5 5" not in repr(df)
448+
assert "<td>5</td>" not in df._repr_html_()
443449

444450
with option_context("display.max_rows", None, "display.min_rows", 12):
445451
# max_rows of None -> never truncate
446452
assert ".." not in repr(df)
453+
assert ".." not in df._repr_html_()
447454

448455
def test_str_max_colwidth(self):
449456
# GH 7856

0 commit comments

Comments
 (0)