Skip to content

Commit 5109712

Browse files
author
y-p
committed
Merge pull request #5649 from y-p/PR_GH5588_again
BUG: repr_html, fix GH5588 for the MultiIndex case
2 parents 286811a + 2f344c1 commit 5109712

File tree

2 files changed

+34
-4
lines changed

2 files changed

+34
-4
lines changed

pandas/core/format.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -846,18 +846,20 @@ def _write_hierarchical_rows(self, fmt_values, indent):
846846

847847
frame = self.frame
848848
ncols = min(len(self.columns), self.max_cols)
849+
nrows = min(len(self.frame), self.max_rows)
850+
849851
truncate = (len(frame) > self.max_rows)
850852

851-
idx_values = frame.index.format(sparsify=False, adjoin=False,
853+
idx_values = frame.index[:nrows].format(sparsify=False, adjoin=False,
852854
names=False)
853855
idx_values = lzip(*idx_values)
854856

855857
if self.fmt.sparsify:
856858

857859
# GH3547
858860
sentinal = com.sentinal_factory()
859-
levels = frame.index.format(sparsify=sentinal, adjoin=False,
860-
names=False)
861+
levels = frame.index[:nrows].format(sparsify=sentinal,
862+
adjoin=False, names=False)
861863
# Truncate row names
862864
if truncate:
863865
levels = [lev[:self.max_rows] for lev in levels]

vb_suite/frame_methods.py

+29-1
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,35 @@ def f(x):
157157
"""
158158

159159
frame_to_html_mixed = Benchmark('df.to_html()', setup,
160-
start_date=datetime(2010, 6, 1))
160+
start_date=datetime(2011, 11, 18))
161+
162+
163+
# truncated repr_html, single index
164+
165+
setup = common_setup + """
166+
nrows=10000
167+
data=randn(nrows,10)
168+
idx=MultiIndex.from_arrays(np.tile(randn(3,nrows/100),100))
169+
df=DataFrame(data,index=idx)
170+
171+
"""
172+
173+
frame_html_repr_trunc_mi = Benchmark('df._repr_html_()', setup,
174+
start_date=datetime(2013, 11, 25))
175+
176+
# truncated repr_html, MultiIndex
177+
178+
setup = common_setup + """
179+
nrows=10000
180+
data=randn(nrows,10)
181+
idx=randn(nrows)
182+
df=DataFrame(data,index=idx)
183+
184+
"""
185+
186+
frame_html_repr_trunc_si = Benchmark('df._repr_html_()', setup,
187+
start_date=datetime(2013, 11, 25))
188+
161189

162190
# insert many columns
163191

0 commit comments

Comments
 (0)