From f95a7bf5b1b294e2f7150091dcf79a1c08cb065c Mon Sep 17 00:00:00 2001 From: y-p Date: Tue, 26 Nov 2013 14:35:54 +0200 Subject: [PATCH 1/2] BUG: to_html doesn't slice index to max_rows before formatting --- pandas/core/format.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pandas/core/format.py b/pandas/core/format.py index 1ca68b8d47e09..cc6f5bd516a19 100644 --- a/pandas/core/format.py +++ b/pandas/core/format.py @@ -819,14 +819,14 @@ def _write_body(self, indent): def _write_regular_rows(self, fmt_values, indent, truncated): ncols = min(len(self.columns), self.max_cols) - + nrows = min(len(self.frame), self.max_rows) fmt = self.fmt._get_formatter('__index__') if fmt is not None: - index_values = self.frame.index.map(fmt) + index_values = self.frame.index[:nrows].map(fmt) else: - index_values = self.frame.index.format() + index_values = self.frame.index[:nrows].format() - for i in range(min(len(self.frame), self.max_rows)): + for i in range(nrows): row = [] row.append(index_values[i]) row.extend(fmt_values[j][i] for j in range(ncols)) From 76eb112f7ff6add16d229cb0df59a86a5b90f92c Mon Sep 17 00:00:00 2001 From: y-p Date: Tue, 26 Nov 2013 14:55:08 +0200 Subject: [PATCH 2/2] VB: add to_html vbench --- vb_suite/frame_methods.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/vb_suite/frame_methods.py b/vb_suite/frame_methods.py index b7754e28629d0..a7c863345b9c5 100644 --- a/vb_suite/frame_methods.py +++ b/vb_suite/frame_methods.py @@ -145,6 +145,20 @@ def f(x): frame_to_string_floats = Benchmark('df.to_string()', setup, start_date=datetime(2010, 6, 1)) +#---------------------------------------------------------------------- +# to_html + +setup = common_setup + """ +nrows=500 +df = DataFrame(randn(nrows, 10)) +df[0]=period_range("2000","2010",nrows) +df[1]=range(nrows) + +""" + +frame_to_html_mixed = Benchmark('df.to_html()', setup, + start_date=datetime(2010, 6, 1)) + # insert many columns setup = common_setup + """