Skip to content

DataFrame.to_html with max_rows and index=False raises IndexError #14998

Closed
@TomAugspurger

Description

@TomAugspurger

Code Sample, a copy-pastable example if possible

In [4]: import pandas as pd

In [5]: import numpy as np

In [6]: df = pd.DataFrame(np.random.randn(100, 2))

In [7]: df.to_html(max_rows=10, index=False)

raises

---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
<ipython-input-7-c16b7151f39c> in <module>()
----> 1 df.to_html(max_rows=10, index=False)

/Users/tom.augspurger/Envs/py3/lib/python3.6/site-packages/pandas-0.19.0+265.gaba7d255a-py3.6-macosx-10.12-x86_64.egg/pandas/core/frame.py in to_html(self, buf, columns, col_space, header, index, na_rep, formatters, float_format, sparsify, index_names, justify, bold_rows, classes, escape, max_rows, max_cols, show_dimensions, notebook, decimal, border)
   1553                                            decimal=decimal)
   1554         # TODO: a generic formatter wld b in DataFrameFormatter
-> 1555         formatter.to_html(classes=classes, notebook=notebook, border=border)
   1556
   1557         if buf is None:

/Users/tom.augspurger/Envs/py3/lib/python3.6/site-packages/pandas-0.19.0+265.gaba7d255a-py3.6-macosx-10.12-x86_64.egg/pandas/formats/format.py in to_html(self, classes, notebook, border)
    698                                       border=border)
    699         if hasattr(self.buf, 'write'):
--> 700             html_renderer.write_result(self.buf)
    701         elif isinstance(self.buf, compat.string_types):
    702             with open(self.buf, 'w') as f:

/Users/tom.augspurger/Envs/py3/lib/python3.6/site-packages/pandas-0.19.0+265.gaba7d255a-py3.6-macosx-10.12-x86_64.egg/pandas/formats/format.py in write_result(self, buf)
   1022         indent += self.indent_delta
   1023         indent = self._write_header(indent)
-> 1024         indent = self._write_body(indent)
   1025
   1026         self.write('</table>', indent)

/Users/tom.augspurger/Envs/py3/lib/python3.6/site-packages/pandas-0.19.0+265.gaba7d255a-py3.6-macosx-10.12-x86_64.egg/pandas/formats/format.py in _write_body(self, indent)
   1184         else:
   1185             for i in range(len(self.frame)):
-> 1186                 row = [fmt_values[j][i] for j in range(len(self.columns))]
   1187                 self.write_tr(row, indent, self.indent_delta, tags=None)
   1188

/Users/tom.augspurger/Envs/py3/lib/python3.6/site-packages/pandas-0.19.0+265.gaba7d255a-py3.6-macosx-10.12-x86_64.egg/pandas/formats/format.py in <listcomp>(.0)
   1184         else:
   1185             for i in range(len(self.frame)):
-> 1186                 row = [fmt_values[j][i] for j in range(len(self.columns))]
   1187                 self.write_tr(row, indent, self.indent_delta, tags=None)
   1188

IndexError: list index out of range
# Paste the output here pd.show_versions() here

INSTALLED VERSIONS

commit: None
python: 3.6.0.final.0
python-bits: 64
OS: Darwin
OS-release: 16.3.0
machine: x86_64
processor: i386
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
LOCALE: en_US.UTF-8

pandas: 0.19.0+265.gaba7d255a
nose: None
pip: 9.0.1
setuptools: 32.3.0
Cython: 0.25.2
numpy: 1.11.3
scipy: 0.18.1
statsmodels: 0.8.0.dev0+fea7e82
xarray: None
IPython: 5.1.0
sphinx: None
patsy: 0.4.1
dateutil: 2.4.1
pytz: 2016.10
blosc: None
bottleneck: 1.2.0
tables: None
numexpr: 2.6.1
matplotlib: 2.0.0rc2
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml: None
bs4: None
html5lib: 0.9999999
httplib2: None
apiclient: None
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: 2.8
s3fs: None
pandas_datareader: None
None

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugIO HTMLread_html, to_html, Styler.apply, Styler.applymap

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions