Skip to content

BUG: repr formating to use iloc rather than getitem for element access (GH5605) #5606

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 28, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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