Skip to content

BUG: Empty DataFrame.style.render raises IndexError #15953

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 Apr 8, 2017 · 1 comment · Fixed by #16441
Closed

BUG: Empty DataFrame.style.render raises IndexError #15953

TomAugspurger opened this issue Apr 8, 2017 · 1 comment · Fixed by #16441
Labels
Bug IO HTML read_html, to_html, Styler.apply, Styler.applymap Output-Formatting __repr__ of pandas objects, to_string

Comments

@TomAugspurger
Copy link
Contributor

Code Sample, a copy-pastable example if possible

In [6]: pd.DataFrame().style.render()
---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
<ipython-input-6-345e1b37074e> in <module>()
----> 1 pd.DataFrame().style.render()

/Users/taugspurger/Envs/dask-dev/lib/python3.6/site-packages/pandas/formats/style.py in render(self)
    416         """
    417         self._compute()
--> 418         d = self._translate()
    419         # filter out empty styles, every cell will have a class
    420         # but the list of props may just be [['', '']].

/Users/taugspurger/Envs/dask-dev/lib/python3.6/site-packages/pandas/formats/style.py in _translate(self)
    252                            "is_visible": True})
    253
--> 254             for c in range(len(clabels[0])):
    255                 cs = [COL_HEADING_CLASS, "level%s" % r, "col%s" % c]
    256                 cs.extend(cell_context.get(

IndexError: list index out of range

Problem description

We assume that there's at least one column (and probably row)

Expected Output

Should match the output of an empty DataFrame in the notebook

@TomAugspurger TomAugspurger added Bug Difficulty Novice IO HTML read_html, to_html, Styler.apply, Styler.applymap Output-Formatting __repr__ of pandas objects, to_string labels Apr 8, 2017
@TomAugspurger TomAugspurger added this to the Next Major Release milestone Apr 8, 2017
sandipchatterjee added a commit to sandipchatterjee/pandas that referenced this issue Apr 10, 2017
Fix attempt for Issue pandas-dev#15953

Handles DataFrames and Series with no rows or columns
using `pd.DataFrame().empty` or `pd.Series().empty`
@JimStearns206
Copy link
Contributor

I'll take a stab at this (I'm at PyCon sprint).

JimStearns206 added a commit to JimStearns206/pandas that referenced this issue May 23, 2017
DataFrame with an index but no column, and one with a column but no index.
Add entry to whatsnew.
JimStearns206 added a commit to JimStearns206/pandas that referenced this issue May 23, 2017
DataFrame with an index but no column, and one with a column but no index.
Add entry to whatsnew.
TomAugspurger pushed a commit that referenced this issue May 23, 2017
…r. (#16441)

* BUG: Render empty DataFrame as empty HTML table w/o raising IndexError.

* TST: Test rendering of 2 empty-ish DataFrames (#15953)

DataFrame with an index but no column, and one with a column but no index.
Add entry to whatsnew.
TomAugspurger pushed a commit to TomAugspurger/pandas that referenced this issue May 29, 2017
…r. (pandas-dev#16441)

* BUG: Render empty DataFrame as empty HTML table w/o raising IndexError.

* TST: Test rendering of 2 empty-ish DataFrames (pandas-dev#15953)

DataFrame with an index but no column, and one with a column but no index.
Add entry to whatsnew.

(cherry picked from commit d9a63d0)
TomAugspurger pushed a commit that referenced this issue May 30, 2017
…r. (#16441)

* BUG: Render empty DataFrame as empty HTML table w/o raising IndexError.

* TST: Test rendering of 2 empty-ish DataFrames (#15953)

DataFrame with an index but no column, and one with a column but no index.
Add entry to whatsnew.

(cherry picked from commit d9a63d0)
stangirala pushed a commit to stangirala/pandas that referenced this issue Jun 11, 2017
…r. (pandas-dev#16441)

* BUG: Render empty DataFrame as empty HTML table w/o raising IndexError.

* TST: Test rendering of 2 empty-ish DataFrames (pandas-dev#15953)

DataFrame with an index but no column, and one with a column but no index.
Add entry to whatsnew.
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 Output-Formatting __repr__ of pandas objects, to_string
Projects
None yet
2 participants