Skip to content

Commit

Permalink
Merge pull request pandas-dev#5606 from jreback/fix_repr
Browse files Browse the repository at this point in the history
BUG: repr formating to use iloc rather than getitem for element access (GH5605)
  • Loading branch information
jreback committed Nov 28, 2013
2 parents 6e86c2c + 53c3181 commit c73b957
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
3 changes: 2 additions & 1 deletion pandas/core/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand Down
16 changes: 16 additions & 0 deletions pandas/tests/test_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c73b957

Please sign in to comment.