From 53c318165ee3ec4c23354355ab44bff75271fc77 Mon Sep 17 00:00:00 2001 From: jreback Date: Wed, 27 Nov 2013 21:16:53 -0500 Subject: [PATCH] BUG: repr formating to use iloc rather than getitem for element access (GH5605) --- pandas/core/format.py | 3 ++- pandas/tests/test_format.py | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/pandas/core/format.py b/pandas/core/format.py index cc6f5bd516a19..8bc74f2ff4c08 100644 --- a/pandas/core/format.py +++ b/pandas/core/format.py @@ -284,6 +284,7 @@ def __init__(self, frame, buf=None, columns=None, col_space=None, self.line_width = line_width self.max_rows = max_rows self.max_cols = max_cols + self.max_rows_displayed = min(max_rows or len(self.frame),len(self.frame)) self.show_dimensions = show_dimensions if justify is None: @@ -483,7 +484,7 @@ def write(buf, frame, column_format, strcols): def _format_col(self, i): formatter = self._get_formatter(i) - return format_array(self.frame.icol(i)[:self.max_rows].get_values(), + return format_array((self.frame.iloc[:self.max_rows_displayed,i]).get_values(), formatter, float_format=self.float_format, na_rep=self.na_rep, space=self.col_space) diff --git a/pandas/tests/test_format.py b/pandas/tests/test_format.py index 8e23176e9d005..fce2bdceba570 100644 --- a/pandas/tests/test_format.py +++ b/pandas/tests/test_format.py @@ -1455,6 +1455,22 @@ def test_repr_html_long(self): assert u('%d rows ') % h in long_repr assert u('2 columns') in long_repr + def test_repr_html_float(self): + max_rows = get_option('display.max_rows') + h = max_rows - 1 + df = pandas.DataFrame({'idx':np.linspace(-10,10,h), 'A':np.arange(1,1+h), 'B': np.arange(41, 41+h) }).set_index('idx') + reg_repr = df._repr_html_() + assert '...' not in reg_repr + assert str(40 + h) in reg_repr + + h = max_rows + 1 + df = pandas.DataFrame({'idx':np.linspace(-10,10,h), 'A':np.arange(1,1+h), 'B': np.arange(41, 41+h) }).set_index('idx') + long_repr = df._repr_html_() + assert '...' in long_repr + assert str(40 + h) not in long_repr + assert u('%d rows ') % h in long_repr + assert u('2 columns') in long_repr + def test_repr_html_long_multiindex(self): max_rows = get_option('display.max_rows') max_L1 = max_rows//2