From d613b9da463e5965798594eb5fc6df9710047120 Mon Sep 17 00:00:00 2001 From: y-p Date: Fri, 6 Dec 2013 00:18:16 +0200 Subject: [PATCH 1/2] BUG: repr_html, fix GH5588 for the MultiIndex case --- pandas/core/format.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/pandas/core/format.py b/pandas/core/format.py index 8bc74f2ff4c08..7135573d48644 100644 --- a/pandas/core/format.py +++ b/pandas/core/format.py @@ -846,9 +846,11 @@ def _write_hierarchical_rows(self, fmt_values, indent): frame = self.frame ncols = min(len(self.columns), self.max_cols) + nrows = min(len(self.frame), self.max_rows) + truncate = (len(frame) > self.max_rows) - idx_values = frame.index.format(sparsify=False, adjoin=False, + idx_values = frame.index[:nrows].format(sparsify=False, adjoin=False, names=False) idx_values = lzip(*idx_values) @@ -856,8 +858,8 @@ def _write_hierarchical_rows(self, fmt_values, indent): # GH3547 sentinal = com.sentinal_factory() - levels = frame.index.format(sparsify=sentinal, adjoin=False, - names=False) + levels = frame.index[:nrows].format(sparsify=sentinal, + adjoin=False, names=False) # Truncate row names if truncate: levels = [lev[:self.max_rows] for lev in levels] From 2f344c1820a9e16841d8189a22fd4d1de9eaa746 Mon Sep 17 00:00:00 2001 From: y-p Date: Fri, 6 Dec 2013 00:31:05 +0200 Subject: [PATCH 2/2] VB: add vbench for truncated repr_html --- vb_suite/frame_methods.py | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/vb_suite/frame_methods.py b/vb_suite/frame_methods.py index a7c863345b9c5..63b2a154c75e9 100644 --- a/vb_suite/frame_methods.py +++ b/vb_suite/frame_methods.py @@ -157,7 +157,35 @@ def f(x): """ frame_to_html_mixed = Benchmark('df.to_html()', setup, - start_date=datetime(2010, 6, 1)) + start_date=datetime(2011, 11, 18)) + + +# truncated repr_html, single index + +setup = common_setup + """ +nrows=10000 +data=randn(nrows,10) +idx=MultiIndex.from_arrays(np.tile(randn(3,nrows/100),100)) +df=DataFrame(data,index=idx) + +""" + +frame_html_repr_trunc_mi = Benchmark('df._repr_html_()', setup, + start_date=datetime(2013, 11, 25)) + +# truncated repr_html, MultiIndex + +setup = common_setup + """ +nrows=10000 +data=randn(nrows,10) +idx=randn(nrows) +df=DataFrame(data,index=idx) + +""" + +frame_html_repr_trunc_si = Benchmark('df._repr_html_()', setup, + start_date=datetime(2013, 11, 25)) + # insert many columns