Skip to content

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

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

Closed
TomAugspurger opened this issue Dec 27, 2016 · 2 comments
Closed
Labels
Bug IO HTML read_html, to_html, Styler.apply, Styler.applymap
Milestone

Comments

@TomAugspurger
Copy link
Contributor

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

@TomAugspurger TomAugspurger added Bug IO HTML read_html, to_html, Styler.apply, Styler.applymap labels Dec 27, 2016
@TomAugspurger TomAugspurger added this to the 0.20.0 milestone Dec 27, 2016
@TomAugspurger TomAugspurger reopened this Dec 27, 2016
@TomAugspurger
Copy link
Contributor Author

I should note that each option works on its own

>>> _ = df.to_html(index=False)
>>> _ = df.to_html(max_rows=10)

@TomAugspurger
Copy link
Contributor Author

PR coming shortly

TomAugspurger added a commit to TomAugspurger/pandas that referenced this issue Dec 27, 2016
closes pandas-dev#14998

Previously raised an IndexError by assuming that
`len(fmt_values)` was always the same length as `len(self.data)`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug IO HTML read_html, to_html, Styler.apply, Styler.applymap
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant