Skip to content

Commit c73b957

Browse files
committed
Merge pull request #5606 from jreback/fix_repr
BUG: repr formating to use iloc rather than getitem for element access (GH5605)
2 parents 6e86c2c + 53c3181 commit c73b957

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

pandas/core/format.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,7 @@ def __init__(self, frame, buf=None, columns=None, col_space=None,
284284
self.line_width = line_width
285285
self.max_rows = max_rows
286286
self.max_cols = max_cols
287+
self.max_rows_displayed = min(max_rows or len(self.frame),len(self.frame))
287288
self.show_dimensions = show_dimensions
288289

289290
if justify is None:
@@ -483,7 +484,7 @@ def write(buf, frame, column_format, strcols):
483484

484485
def _format_col(self, i):
485486
formatter = self._get_formatter(i)
486-
return format_array(self.frame.icol(i)[:self.max_rows].get_values(),
487+
return format_array((self.frame.iloc[:self.max_rows_displayed,i]).get_values(),
487488
formatter, float_format=self.float_format,
488489
na_rep=self.na_rep,
489490
space=self.col_space)

pandas/tests/test_format.py

+16
Original file line numberDiff line numberDiff line change
@@ -1455,6 +1455,22 @@ def test_repr_html_long(self):
14551455
assert u('%d rows ') % h in long_repr
14561456
assert u('2 columns') in long_repr
14571457

1458+
def test_repr_html_float(self):
1459+
max_rows = get_option('display.max_rows')
1460+
h = max_rows - 1
1461+
df = pandas.DataFrame({'idx':np.linspace(-10,10,h), 'A':np.arange(1,1+h), 'B': np.arange(41, 41+h) }).set_index('idx')
1462+
reg_repr = df._repr_html_()
1463+
assert '...' not in reg_repr
1464+
assert str(40 + h) in reg_repr
1465+
1466+
h = max_rows + 1
1467+
df = pandas.DataFrame({'idx':np.linspace(-10,10,h), 'A':np.arange(1,1+h), 'B': np.arange(41, 41+h) }).set_index('idx')
1468+
long_repr = df._repr_html_()
1469+
assert '...' in long_repr
1470+
assert str(40 + h) not in long_repr
1471+
assert u('%d rows ') % h in long_repr
1472+
assert u('2 columns') in long_repr
1473+
14581474
def test_repr_html_long_multiindex(self):
14591475
max_rows = get_option('display.max_rows')
14601476
max_L1 = max_rows//2

0 commit comments

Comments
 (0)